Skip to content

fix(go): return error instead of panic on S2 decode failure#3166

Open
atharvalade wants to merge 3 commits intoapache:masterfrom
atharvalade:fix/go-sdk-s2-decode-panic
Open

fix(go): return error instead of panic on S2 decode failure#3166
atharvalade wants to merge 3 commits intoapache:masterfrom
atharvalade:fix/go-sdk-s2-decode-panic

Conversation

@atharvalade
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #3129

Rationale

Library code should never panic on bad server data — a truncated or corrupt S2-compressed message currently crashes the entire Go client process.

What changed?

DeserializeFetchMessagesResponse called panic() when s2.Decode failed on a malformed compressed payload. Callers had no way to recover.

Replaced panic(...) with return nil, fmt.Errorf(...) so the error propagates through the existing error return value. Added unit tests covering the malformed S2 path, the no-compression path, and the empty-payload path.

Local Execution

  • Passed
  • Pre-commit hooks ran (license-headers, trailing-whitespace, trailing-newline all clean on changed files)

AI Usage

  1. Opus 4.6
  2. Guided the fix and test scaffolding
  3. Ran go test, go vet, and CI lint scripts locally; all pass
  4. Yes, all code can be explained

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.80%. Comparing base (611fca0) to head (8577519).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3166      +/-   ##
============================================
- Coverage     74.10%   72.80%   -1.30%     
  Complexity      943      943              
============================================
  Files          1159     1117      -42     
  Lines        102033    96111    -5922     
  Branches      79083    73289    -5794     
============================================
- Hits          75607    69976    -5631     
+ Misses        23765    23591     -174     
+ Partials       2661     2544     -117     
Components Coverage Δ
Rust Core 73.54% <ø> (-1.79%) ⬇️
Java SDK 62.30% <ø> (+2.15%) ⬆️
C# SDK 69.42% <ø> (+0.04%) ⬆️
Python SDK 81.43% <ø> (ø)
Node SDK 91.53% <ø> (ø)
Go SDK 39.63% <100.00%> (+0.20%) ⬆️
Files with missing lines Coverage Δ
...nary_serialization/binary_response_deserializer.go 86.02% <100.00%> (+2.45%) ⬆️

... and 101 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

payloadSlice, err = s2.Decode(nil, payloadSlice)
if err != nil {
panic("iggy: failed to decode s2 payload: " + err.Error())
return nil, fmt.Errorf("iggy: failed to decode s2 payload: %w", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
return nil, fmt.Errorf("iggy: failed to decode s2 payload: %w", err)
return nil, fmt.Errorf("failed to decode s2 payload: %w", err)

Copy link
Copy Markdown
Contributor

@chengxilo chengxilo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

go-sdk: panic on malformed S2-compressed poll response

2 participants