Repository navigation
fix: add stack trace to AbortSignal.timeout errorsfix: add stack trace to AbortSignal.timeout errors #25339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add stack trace to AbortSignal.timeout errorsfix: add stack trace to AbortSignal.timeout errors #25339
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { expect, test, describe } from "bun:test"; | ||
|
|
||
| describe("AbortSignal.timeout stack trace", () => { | ||
| test("should include stack trace pointing to where AbortSignal.timeout() was called", async () => { | ||
| // This test verifies fix for issue #25182 | ||
| // The stack trace should point to where AbortSignal.timeout() was called, | ||
| // not just where the timeout was triggered internally | ||
|
|
||
| async function myFunction() { | ||
| const signal = AbortSignal.timeout(50); | ||
| await new Promise((resolve, reject) => { | ||
| signal.addEventListener('abort', () => { | ||
| reject(signal.reason); | ||
| }); | ||
| setTimeout(resolve, 1000); | ||
| }); | ||
| } | ||
|
Comment on lines
+9
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid Both tests use Also applies to: 41-45 🤖 Prompt for AI Agents |
||
|
|
||
| try { | ||
| await myFunction(); | ||
| expect.unreachable("Should have thrown"); | ||
| } catch (e: any) { | ||
| expect(e instanceof DOMException).toBe(true); | ||
| expect(e.name).toBe("TimeoutError"); | ||
| expect(e.message).toBe("The operation timed out."); | ||
|
|
||
| // The stack trace should include 'myFunction' | ||
| // since that's where AbortSignal.timeout() was called | ||
| const stack = e.stack; | ||
| expect(stack).toBeDefined(); | ||
| expect(typeof stack).toBe("string"); | ||
|
|
||
| // Check that stack trace includes the calling function | ||
| // This is the key fix - previously this would be empty or only have internals | ||
| expect(stack).toInclude("myFunction"); | ||
| } | ||
| }); | ||
|
|
||
| test("stack trace should include the test file name", async () => { | ||
| try { | ||
| const signal = AbortSignal.timeout(10); | ||
| await new Promise((resolve, reject) => { | ||
| signal.addEventListener('abort', () => reject(signal.reason)); | ||
| setTimeout(resolve, 1000); | ||
| }); | ||
| } catch (e: any) { | ||
| // Stack should reference this test file | ||
| expect(e.stack).toInclude("abort-signal-timeout-stack.test.ts"); | ||
| } | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.