[PR #12809] fix(opencode): expand Error properties in logs for better diagnostics #14383

Open
opened 2026-02-16 18:19:10 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12809

State: open
Merged: No


Fixes #12808

What

Error logs previously only printed e.message, losing structured context like providerID, modelID, url, statusCode, cause chain, and stack traces.

Changes

  • formatError in log.ts now expands all own properties of an Error via Object.getOwnPropertyNames, recursing into nested Errors (e.g. cause)
  • build calls formatError when a value is an instanceof Error, emitting each property as a separate key=value pair
  • Updated unhandledRejection/uncaughtException handlers in index.ts, worker.ts, thread.ts to pass the full error object instead of e.message
  • Updated MCP error logging to pass e instead of e.message
  • Fixed a copy-paste bug: fetchResourcesForClient logged "failed to get prompts" instead of "failed to get resources"

Backward compatible

Callers that still pass e.message (a string) work exactly as before. Only callers that pass an Error object get richer output.

Verification

  • bun run typecheck passes
  • Before: ERROR ... e=ProviderModelNotFoundError rejection
  • After: ERROR ... name=ProviderModelNotFoundError message=ProviderModelNotFoundError data={"providerID":"openai","modelID":"gpt-5-turbo"} stack=... rejection
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12809 **State:** open **Merged:** No --- Fixes #12808 ## What Error logs previously only printed `e.message`, losing structured context like `providerID`, `modelID`, `url`, `statusCode`, `cause` chain, and stack traces. ## Changes - `formatError` in `log.ts` now expands all own properties of an Error via `Object.getOwnPropertyNames`, recursing into nested Errors (e.g. `cause`) - `build` calls `formatError` when a value is an `instanceof Error`, emitting each property as a separate `key=value` pair - Updated `unhandledRejection`/`uncaughtException` handlers in `index.ts`, `worker.ts`, `thread.ts` to pass the full error object instead of `e.message` - Updated MCP error logging to pass `e` instead of `e.message` - Fixed a copy-paste bug: `fetchResourcesForClient` logged "failed to get prompts" instead of "failed to get resources" ## Backward compatible Callers that still pass `e.message` (a string) work exactly as before. Only callers that pass an Error object get richer output. ## Verification - `bun run typecheck` passes - Before: `ERROR ... e=ProviderModelNotFoundError rejection` - After: `ERROR ... name=ProviderModelNotFoundError message=ProviderModelNotFoundError data={"providerID":"openai","modelID":"gpt-5-turbo"} stack=... rejection`
yindo added the pull-request label 2026-02-16 18:19:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14383