Skip to content

Commit 7e96035

Browse files
committed
Fix unresolved promise
1 parent 0751b2a commit 7e96035

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/seroval/src/binary/deserializer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface DeserializerContext {
6666
refs: Map<number, { value: unknown }>;
6767
plugins?: Plugin<any, any>[];
6868
root: PromiseConstructorResolver;
69+
rootFound: boolean;
6970
done: boolean;
7071
buffer: Uint8Array;
7172
marker: Map<number, SerovalBinaryType>;
@@ -81,6 +82,7 @@ export function createDeserializerContext(
8182
done: false,
8283
buffer: new Uint8Array(),
8384
root: PROMISE_CONSTRUCTOR(),
85+
rootFound: false,
8486
read: options.read,
8587
onError: options.onError,
8688
refs: options.refs,
@@ -627,6 +629,7 @@ async function deserializePlugin(ctx: DeserializerContext) {
627629

628630
async function deserializeRoot(ctx: DeserializerContext) {
629631
const reference = await deserializeRef(ctx, SerovalBinaryType.Root);
632+
ctx.rootFound = true;
630633
ctx.root.s(reference);
631634
}
632635

@@ -782,7 +785,10 @@ async function drain(ctx: DeserializerContext) {
782785
while (true) {
783786
if (ctx.buffer.length === 0) {
784787
if (ctx.done) {
785-
return;
788+
if (ctx.rootFound) {
789+
return;
790+
}
791+
throw new SerovalMalformedBinarySourceError();
786792
}
787793
await readChunk(ctx);
788794
} else {

0 commit comments

Comments
 (0)