Skip to content

Conversation

@craigvandotcom
Copy link

Problem

When errors occur during session execution (e.g., "Process exited unexpectedly"), the actual error details are lost in the logs:

[16:21:21.424] [remote]: launch error {}

The error object appears as {} because JSON.stringify() doesn't capture Error properties (message, stack, name) - they're not enumerable.

Solution

Added a serializeForLog() helper function that properly handles Error objects by explicitly extracting their non-enumerable properties.

Before

[16:21:21.424] [remote]: launch error {}

After

[16:21:21.424] [remote]: launch error {"name":"Error","message":"Connection refused","stack":"Error: Connection refused\n    at ..."}

Changes

  • Added serializeForLog() helper function in src/ui/logger.ts
  • Updated logToFile() to use the new helper
  • Updated sendToRemoteServer() to use the same helper for consistency
  • Added unit tests in src/ui/logger.test.ts

Testing

npx vitest run src/ui/logger.test.ts

All 7 tests pass:

  • String passthrough
  • Plain object serialization
  • Error serialization with name, message, stack
  • TypeError with correct name
  • Additional enumerable properties on errors
  • null/undefined handling
  • number/boolean handling

Impact

This fix will help users and maintainers debug "Process exited unexpectedly" errors by capturing the actual error details in logs at ~/.happy/logs/.


🤖 Generated with Claude Code

Error objects logged with logger.debug() were appearing as {} because
JSON.stringify() doesn't capture non-enumerable Error properties (message,
stack, name).

Added serializeForLog() helper that explicitly extracts Error properties,
making debug logs actually useful for diagnosing issues like "Process
exited unexpectedly".

Before: [16:21:21.424] [remote]: launch error {}
After:  [16:21:21.424] [remote]: launch error {"name":"Error","message":"...","stack":"..."}

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Craig van Heerden <[email protected]>
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