Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 5, 2023
1 parent 8aad183 commit f0ec11f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/async/deserializeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export function createTsonParseAsyncInner(opts: TsonAsyncOptions) {
let nextValue = await instance.next();

while (!nextValue.done) {
console.log("got next value", nextValue);
nextValue.value.split("\n").forEach(readLine);

nextValue = await instance.next();
Expand Down
6 changes: 6 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ export class TsonPromiseRejectionError extends TsonError {
super(`Promise rejected`, { cause });
this.name = "TsonPromiseRejectionError";
}

static from(cause: unknown) {
return cause instanceof Error
? cause
: new TsonPromiseRejectionError(cause);
}
}
6 changes: 4 additions & 2 deletions src/handlers/tsonPromise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ test("stringify and parse promise with a promise", async () => {
});

// let's do it over an actual network connection
test("stringify and parse promise with a promise over a network connection", async () => {
test.only("stringify and parse promise with a promise over a network connection", async () => {

Check failure on line 401 in src/handlers/tsonPromise.test.ts

View workflow job for this annotation

GitHub Actions / lint

test.only not permitted
interface Obj {
promise: Promise<{
anotherPromise: Promise<number>;
Expand Down Expand Up @@ -530,7 +530,9 @@ test("does not crash node when it receives a promise rejection", async () => {

const err = await waitError(result.foo);

expect(err).toMatchInlineSnapshot("[TsonError: Promise rejected on server]");
expect(err).toMatchInlineSnapshot(
"[TsonPromiseRejectionError: Promise rejected]",
);
});

test("stringify promise rejection", async () => {
Expand Down
7 changes: 5 additions & 2 deletions src/handlers/tsonPromise.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TsonAsyncType } from "../async/asyncTypes.js";
import { TsonPromiseRejectionError } from "../errors.js";

function isPromise(value: unknown): value is Promise<unknown> {
return (
Expand Down Expand Up @@ -31,7 +32,9 @@ export const tsonPromise: TsonAsyncType<MyPromise, SerializedPromiseValue> = {

const [status, result] = value.value;

status === PROMISE_RESOLVED ? resolve(result as any) : reject(result);
status === PROMISE_RESOLVED
? resolve(result as any)
: reject(TsonPromiseRejectionError.from(result));

opts.onDone();
}
Expand Down Expand Up @@ -84,7 +87,7 @@ export const tsonAsyncIterator: TsonAsyncType<
}

case ITERATOR_ERROR: {
throw value[1];
throw TsonPromiseRejectionError.from(value[1]);
}

case ITERATOR_VALUE: {
Expand Down

0 comments on commit f0ec11f

Please sign in to comment.