Skip to content

fix(logging): use object cause in TRPCErrors so event name is logged correctly#749

Merged
danadajian merged 4 commits intomainfrom
fix/trpc-error-cause-logging
Mar 26, 2026
Merged

fix(logging): use object cause in TRPCErrors so event name is logged correctly#749
danadajian merged 4 commits intomainfrom
fix/trpc-error-cause-logging

Conversation

@danadajian
Copy link
Copy Markdown
Contributor

Summary

  • TRPCError's getCauseFromUnknown helper wraps string cause values in new Error(String(cause)), causing JSON.stringify to serialize them as {} (since Error properties are non-enumerable)
  • Changed all cause: 'EVENT_NAME' strings to cause: { event: 'EVENT_NAME' } objects — tRPC then uses Object.assign(new UnknownCauseError(), cause), making event an enumerable property
  • Updated server.ts to spread cause (...cause) so the event key surfaces as a top-level field in structured log output alongside path, code, and message

Changes

  • app/backend/src/getGroupedKeys.tsCOMMIT_HASH_NOT_FOUND, NO_NEW_OR_DIFF_IMAGES
  • app/backend/src/fetchCurrentPage.tsPAGE_NOT_FOUND, INVALID_FILE_NAME
  • app/backend/src/updateCommitStatus.tsCOMMIT_STATUS_UPDATE_FAILED
  • app/backend/src/getOctokit.tsMISSING_SECRETS_FILE, SECRETS_PARSE_ERROR, MISSING_GITHUB_TOKEN
  • app/backend/src/acceptVisualChanges.tsVISUAL_CHANGE_ACCEPTANCE_BLOCKED, MISSING_IDENTIFIER
  • app/server.ts — spread cause into log payload instead of passing as nested object

Test plan

  • Trigger a COMMIT_HASH_NOT_FOUND error (e.g. load the app with a non-existent commit hash) and verify server logs show "event":"COMMIT_HASH_NOT_FOUND" as a top-level field rather than "cause":{}
  • Confirm existing backend unit tests still pass: bunx nx test backend

Generated with Claude Code

danadajian and others added 4 commits March 26, 2026 17:27
…correctly

tRPC's getCauseFromUnknown wraps string causes in new Error(), which
JSON.stringify serializes as {}. Using { event: 'EVENT_NAME' } objects
instead lets the event property spread into the structured log output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@danadajian danadajian merged commit f58cd23 into main Mar 26, 2026
3 checks passed
@danadajian danadajian deleted the fix/trpc-error-cause-logging branch March 26, 2026 22:38
@eg-oss-ci
Copy link
Copy Markdown

🎉 This PR is included in version 1.41.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants