Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions libs/deepagents/src/backends/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Comment on lines +361 to +362
Copy link

Copilot AI Apr 2, 2026

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 string message property) and/or providing a clearer fallback for null/undefined (e.g., "Unknown error").

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new catch-handling behavior isn’t covered by existing unit tests. Consider adding tests that simulate read() failing with non-Error thrown values (e.g., a thrown string/number/object) to verify the returned error string is stable and not undefined.

Suggested change
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 uses AI. Check for mistakes.
}
}

Expand Down Expand Up @@ -449,8 +449,9 @@ export class StoreBackend implements BackendProtocolV2 {
const storeValue = this.convertFileDataToStoreValue(newFileData);
await store.put(namespace, filePath, storeValue);
return { path: filePath, filesUpdate: null, occurrences: occurrences };
} catch (e: any) {
return { error: `Error: ${e.message}` };
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e);
Copy link

Copilot AI Apr 2, 2026

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.

Suggested change
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 uses AI. Check for mistakes.
return { error: `Error: ${msg}` };
Comment on lines 449 to +454
Copy link

Copilot AI Apr 2, 2026

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.

Copilot uses AI. Check for mistakes.
}
}

Expand Down
Loading