-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[fix]: expose error cause in UnderstudyCommandException
#1705
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
Merged
seanmcguire12
merged 5 commits into
main
from
seanmcguire/stg-1310-include-stack-trace-in-understudycommandexception
Feb 19, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
145e088
expose cause in UnderstudyCommandException
seanmcguire12 fbe2e76
changeset
seanmcguire12 8e78a14
check type before accessing e.message and e.stack
seanmcguire12 5b39abe
update export surface test
seanmcguire12 e2047d6
dont double wrap errors
seanmcguire12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@browserbasehq/stagehand": patch | ||
| --- | ||
|
|
||
| include error cause in UnderstudyCommandException |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| UnderstudyCommandException, | ||
| StagehandError, | ||
| } from "../lib/v3/types/public/sdkErrors.js"; | ||
|
|
||
| describe("UnderstudyCommandException", () => { | ||
| it("extends StagehandError", () => { | ||
| const err = new UnderstudyCommandException("test"); | ||
| expect(err).toBeInstanceOf(StagehandError); | ||
| expect(err).toBeInstanceOf(Error); | ||
| }); | ||
|
|
||
| it("has the correct name", () => { | ||
| const err = new UnderstudyCommandException("test"); | ||
| expect(err.name).toBe("UnderstudyCommandException"); | ||
| }); | ||
|
|
||
| it("preserves the message", () => { | ||
| const err = new UnderstudyCommandException("something broke"); | ||
| expect(err.message).toBe("something broke"); | ||
| }); | ||
|
|
||
| it("stores the original error as cause when provided", () => { | ||
| const original = new Error("root cause"); | ||
| const err = new UnderstudyCommandException("wrapper message", original); | ||
|
|
||
| expect(err.cause).toBe(original); | ||
| expect((err.cause as Error).message).toBe("root cause"); | ||
| expect((err.cause as Error).stack).toBeDefined(); | ||
| }); | ||
|
|
||
| it("stores non-Error cause values", () => { | ||
| const err = new UnderstudyCommandException("failed", "string cause"); | ||
| expect(err.cause).toBe("string cause"); | ||
| }); | ||
|
|
||
| it("has undefined cause when none is provided", () => { | ||
| const err = new UnderstudyCommandException("no cause"); | ||
| expect(err.cause).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("generates its own stack trace", () => { | ||
| const err = new UnderstudyCommandException("test"); | ||
| expect(err.stack).toBeDefined(); | ||
| expect(err.stack).toContain("UnderstudyCommandException"); | ||
| }); | ||
|
|
||
| it("preserves the original stack via cause for debugging", () => { | ||
| function deepFunction() { | ||
| throw new Error("deep error"); | ||
| } | ||
|
|
||
| let original: Error; | ||
| try { | ||
| deepFunction(); | ||
| } catch (e) { | ||
| original = e as Error; | ||
| } | ||
|
|
||
| const wrapped = new UnderstudyCommandException(original!.message, original); | ||
|
|
||
| // The wrapper has its own stack | ||
| expect(wrapped.stack).toBeDefined(); | ||
| // The original stack is accessible via cause | ||
| expect((wrapped.cause as Error).stack).toContain("deepFunction"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.