Skip to content

Add ResponseDecodeError for richer client decode failure debugging#73

Merged
cubahno merged 1 commit into
mainfrom
ig/improve-failed-dec-err
Apr 20, 2026
Merged

Add ResponseDecodeError for richer client decode failure debugging#73
cubahno merged 1 commit into
mainfrom
ig/improve-failed-dec-err

Conversation

@cubahno
Copy link
Copy Markdown
Collaborator

@cubahno cubahno commented Apr 20, 2026

Summary

  • Adds ResponseDecodeError struct to pkg/runtime with structured fields (StatusCode, ContentType, ContentLength, TargetType, Body) for programmatic inspection of decode failures
  • Updates client.tmpl to return &ResponseDecodeError{...} instead of generic fmt.Errorf("error decoding response: %w", err) at both error-response and success-response unmarshal paths
  • Body is intentionally excluded from .Error() to prevent PII leakage into logs, but accessible via errors.As for developers who need it

Motivation

The previous error message - error decoding response: <unmarshal error> - was hard to debug. It lacked context about what HTTP status was received, what content type the server returned, how large the body was, or what Go type was being targeted. A common suggestion was to
include the body in the error string, but that risks leaking sensitive data into logs and error tracking systems.

ResponseDecodeError gives everything needed:

  • The .Error() string includes metadata for log-friendly debugging
  • errors.As gives programmatic access to all fields including the raw body, when the developer explicitly opts in

@cubahno cubahno force-pushed the ig/improve-failed-dec-err branch from 42e0db6 to 11b5eb8 Compare April 20, 2026 14:35
@cubahno cubahno marked this pull request as ready for review April 20, 2026 14:40
@cubahno cubahno merged commit fd52447 into main Apr 20, 2026
3 checks passed
@cubahno cubahno deleted the ig/improve-failed-dec-err branch April 20, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant