Skip to content

Commit eff9c3b

Browse files
authored
Merge pull request #1014 from thefrontside/v4-nested-scope-points
✨ properly propagate errors from nested scopes
2 parents c64dc04 + 02b2e94 commit eff9c3b

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

lib/delimiter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ export class Delimiter<T>
5050
if (this.finalized) {
5151
return;
5252
}
53-
this.outcome = outcome;
53+
this.outcome =
54+
(this.outcome && this.outcome.exists && !this.outcome.value.ok)
55+
? this.outcome
56+
: outcome;
5457
this.level++;
5558
if (!this.routine) {
5659
this.finalized = true;
57-
this.future.resolve(outcome);
60+
this.future.resolve(this.outcome);
5861
} else {
59-
this.routine.return(Ok(outcome));
62+
this.routine.return(Ok(this.outcome));
6063
}
6164
}
6265

test/scoped.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { box } from "../lib/box.ts";
12
import {
23
createContext,
34
resource,
@@ -157,21 +158,21 @@ describe("scoped", () => {
157158
}));
158159
});
159160

160-
it.skip("throws errors at the correct point when there are multiple nested scopes", async () => {
161+
it("throws errors at the correct point when there are multiple nested scopes", async () => {
161162
let task = run(function* () {
162163
return yield* scoped(function* () {
163164
yield* spawn(function* () {
164165
yield* sleep(1);
165166
throw new Error("boom!");
166167
});
167168

168-
try {
169-
return yield* scoped(function* () {
170-
yield* suspend();
171-
});
172-
} catch (error) {
173-
return error;
174-
}
169+
yield* box(() =>
170+
scoped(function* () {
171+
yield* scoped(function* () {
172+
yield* suspend();
173+
});
174+
})
175+
);
175176
});
176177
});
177178

test/spawn.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ describe("spawn", () => {
122122

123123
await expect(root.halt()).rejects.toHaveProperty("message", "moo");
124124
await expect(child!.halt()).rejects.toHaveProperty("message", "moo");
125-
await expect(root.halt()).rejects.toHaveProperty("message", "moo");
126125
});
127126

128127
it("halts when child finishes during asynchronous halt", async () => {

0 commit comments

Comments
 (0)