-
Notifications
You must be signed in to change notification settings - Fork 159
fix: safely handle non-Error thrown values in StoreBackend #418
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -358,8 +358,8 @@ export class StoreBackend implements BackendProtocolV2 { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const lines = fileDataV2.content.split("\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const selected = lines.slice(offset, offset + limit); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { content: selected.join("\n"), mimeType: fileDataV2.mimeType }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e: any) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { error: e.message }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e: unknown) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { error: e instanceof Error ? e.message : String(e) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { error: e instanceof Error ? e.message : String(e) }; | |
| let message: string | undefined; | |
| if (e instanceof Error) { | |
| message = e.message; | |
| } else if (typeof e === "string") { | |
| message = e; | |
| } else if ( | |
| e !== null && | |
| typeof e === "object" && | |
| "message" in e && | |
| typeof (e as { message?: unknown }).message === "string" | |
| ) { | |
| message = (e as { message: string }).message; | |
| } else if ( | |
| typeof e === "number" || | |
| typeof e === "boolean" || | |
| typeof e === "bigint" || | |
| typeof e === "symbol" | |
| ) { | |
| message = String(e); | |
| } | |
| return { | |
| error: message && message.length > 0 | |
| ? message | |
| : "Unknown error while reading file", | |
| }; |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: String(e) will render thrown objects as "[object Object]" and may also produce "undefined"/"null" strings. If you want actionable error text for non-Error throws, consider extracting a string message property when present and using a friendlier fallback for nullish values.
| const msg = e instanceof Error ? e.message : String(e); | |
| const msg = | |
| e instanceof Error | |
| ? e.message | |
| : typeof e === "string" | |
| ? e | |
| : e && typeof (e as any).message === "string" | |
| ? (e as any).message | |
| : "Unknown error"; |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description/test plan mention readFileContent / editFileContent, but the changes are in read() and edit(). Please update the PR description (and any related docs) so reviewers and future readers can match the change to the correct methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For non-Error thrown values,
String(e)will produce unhelpful output for objects (e.g.,throw { foo: 1 }becomes "[object Object]"). If the intent is to preserve a meaningful message for thrown objects, consider handling common "error-like" shapes (e.g., object with a stringmessageproperty) and/or providing a clearer fallback fornull/undefined(e.g., "Unknown error").