Skip to content

fix: log JSON encode errors in writeJSON#331

Merged
tomasz-tomczyk merged 1 commit intomainfrom
fix/writejson-error-logging
Apr 21, 2026
Merged

fix: log JSON encode errors in writeJSON#331
tomasz-tomczyk merged 1 commit intomainfrom
fix/writejson-error-logging

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

  • writeJSON now logs encode failures via log.Printf instead of silently dropping them
  • Consistent with existing log.Printf usage elsewhere in server.go
  • No panic/fatal — a failed encode on one response doesn't crash the server

Test plan

  • go vet ./... clean
  • go test -race -count=1 ./... passes
  • Reviewed by Go expert agent — approved

🤖 Generated with Claude Code

If json.NewEncoder(w).Encode(v) fails (broken pipe, unencodable type),
the error was discarded with `_ =`, leaving the client with a partial or
empty 200 response and no server-side indication of failure. Log the
error so it is visible in server output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tomasz-tomczyk tomasz-tomczyk force-pushed the fix/writejson-error-logging branch from 9c81055 to 619adc1 Compare April 21, 2026 21:14
@tomasz-tomczyk tomasz-tomczyk merged commit 62ea548 into main Apr 21, 2026
4 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the fix/writejson-error-logging branch April 21, 2026 21:25
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