Skip to content

Fix CLI verbose error formatting#1613

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/cli-verbose-error-format
Jun 25, 2026
Merged

Fix CLI verbose error formatting#1613
ChiragAgg5k merged 1 commit into
mainfrom
fix/cli-verbose-error-format

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What

Fix CLI verbose and report error logging so compiled Bun binaries print a compact stack trace instead of dumping bundled source context from the raw error object.

Why

console.error(err) can include noisy $bunfs bundled code frames in compiled CLI binaries, making --verbose output hard to read. Formatting the error explicitly preserves the stack plus useful Appwrite SDK fields like code, type, and response.

Testing

  • php example.php cli
  • composer lint-twig
  • npm run build in examples/cli
  • git diff --check
  • Manually forced getValidAccessToken() through the CLI helper after relogin; refresh succeeded and returned a fresh openid email profile account.admin access token while persisting the rotated credentials through the normal path.

@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces raw console.error(err) calls in the verbose and report paths with a new formatErrorForLog helper that serialises the error to a clean string — preserving the stack trace and inserting Appwrite-specific fields (code, type, response) between the error header and the frame list.

  • formatErrorForLog is exported and handles the known Appwrite SDK error fields via hasOwnProperty, with a JSON.stringify/String fallback and a try/catch for non-serialisable values.
  • The two console.error(err) call sites in parseError (verbose branch and report branch) are updated to console.error(formatErrorForLog(err)).

Confidence Score: 4/5

The change is narrowly scoped to the verbose/report error-display paths; it does not alter control flow, error handling logic, or any data written to disk or the network.

Both call sites are updated consistently and the new helper correctly falls back from JSON.stringify to String() for non-serialisable values. The only note is the dead "undefined" initialiser, which is cosmetic.

No files require special attention.

Important Files Changed

Filename Overview
templates/cli/lib/parser.ts Adds formatErrorForLog to produce a clean, structured string from error objects (stack + Appwrite-specific fields), replacing raw console.error(err) in verbose/report paths

Reviews (1): Last reviewed commit: "Fix CLI verbose error formatting" | Re-trigger Greptile

Comment on lines +676 to +684
let detail = "undefined";
try {
detail =
typeof value === "string"
? JSON.stringify(value)
: JSON.stringify(value) ?? String(value);
} catch {
detail = String(value);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The detail variable is initialised to "undefined" but this value is never actually used: the try block always assigns detail (the nullish-coalescing fallback ensures a non-undefined string even when JSON.stringify returns JS undefined), and the catch block overwrites it with String(value). The dead initialiser is misleading because it suggests there is a path that produces the string "undefined" outside of the String(undefined) call.

Suggested change
let detail = "undefined";
try {
detail =
typeof value === "string"
? JSON.stringify(value)
: JSON.stringify(value) ?? String(value);
} catch {
detail = String(value);
}
let detail: string;
try {
detail =
typeof value === "string"
? JSON.stringify(value)
: JSON.stringify(value) ?? String(value);
} catch {
detail = String(value);
}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ChiragAgg5k ChiragAgg5k merged commit 3dbb283 into main Jun 25, 2026
59 checks passed
@ChiragAgg5k ChiragAgg5k deleted the fix/cli-verbose-error-format branch June 25, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant