Repository navigation
fix: never send a stack trace in a server error response; an unavailable remote config is a 502 #1788
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
Open
ralphstodomingo
wants to merge
4
commits into
main
Choose a base branch
from
fix/1787-server-error-bodies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+383
−10
Open
fix: never send a stack trace in a server error response; an unavailable remote config is a 502 #1788
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
41b454e
fix: never send a stack trace in a server error response; an unavaila…
ralphstodomingo b378ee0
fix: drop every stack frame from a session error, with or without a s…
ralphstodomingo 91235eb
fix: keep tokens out of remote-config errors; log once with the ref; …
ralphstodomingo 236186b
fix: an empty NamedError message falls back to the fixed text
ralphstodomingo 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
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,48 @@ | ||
| import { NamedError } from "@opencode-ai/core/util/error" | ||
|
|
||
| // What the server's error handlers send back. For an error they don't recognise, a fixed message and a ref: never | ||
| // the error's own text, stack or file paths. Each handler logs the full error once, under the same ref. | ||
|
|
||
| /** HTTP status for an error the handlers know by name: a remote the server depends on failed (502). */ | ||
| export function upstreamStatus(name: string): 502 | undefined { | ||
| return name === "ConfigRemoteUnavailableError" ? 502 : undefined | ||
|
ralphstodomingo marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| // An indented `at …` line: how V8, JSC and Bun print every stack frame, with or without a source location | ||
| // (`at new Promise (<anonymous>)`, `at async Promise.all (index 0)`). | ||
| const FRAME = /^\s+at\s/ | ||
|
|
||
| export const UNEXPECTED = "Unexpected server error. Check server logs for details." | ||
|
ralphstodomingo marked this conversation as resolved.
Resolved
|
||
|
|
||
| /** A reference for one failure: the handler logs the error under it, and an unknown error's response carries it. */ | ||
| export function errorRef(): string { | ||
| return `err_${crypto.randomUUID().slice(0, 8)}` | ||
| } | ||
|
|
||
| /** A NamedError keeps its text in `data.message`; its own `message` is only its name. */ | ||
| function namedErrorMessage(err: unknown): string | undefined { | ||
| if (typeof err !== "object" || err === null || !("data" in err)) return undefined | ||
| const data = (err as { data?: unknown }).data | ||
| if (typeof data !== "object" || data === null) return undefined | ||
| const message = (data as { message?: unknown }).message | ||
| return typeof message === "string" ? message : undefined | ||
| } | ||
|
|
||
| /** | ||
| * An error's message without stack-frame lines (some errors carry frames in the message itself), for a client | ||
| * that has to tell a user why their own request failed, such as a session's error event. | ||
| */ | ||
| export function clientMessage(err: unknown): string { | ||
| const raw = namedErrorMessage(err) ?? (err instanceof Error ? err.message : String(err)) | ||
| const message = raw | ||
| .split("\n") | ||
| .filter((line) => !FRAME.test(line)) | ||
| .join("\n") | ||
| .trim() | ||
| return message || UNEXPECTED | ||
| } | ||
|
|
||
| /** The response body for an error no handler recognises: the fixed message and the ref it was logged under. */ | ||
| export function unknownErrorBody(ref: string) { | ||
| return new NamedError.Unknown({ message: UNEXPECTED, ref }).toObject() | ||
| } | ||
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
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
Oops, something went wrong.
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.