Skip to content

fix: don't panic when marshaling a zero DynamoDBAttributeValue - #656

Open
aad1tyaaaaa wants to merge 1 commit into
aws:mainfrom
aad1tyaaaaa:fix-attributevalue-marshal-zero
Open

aad1tyaaaaa wants to merge 1 commit into
aws:mainfrom
aad1tyaaaaa:fix-attributevalue-marshal-zero

Conversation

@aad1tyaaaaa

Copy link
Copy Markdown

Fixes #655

A zero DynamoDBAttributeValue (an unset field, a missing image-map key, or the value left by a failed UnmarshalJSON) has dataType 0 (DataTypeBinary) and a nil value, so MarshalJSON panicked on av.value.([]byte). It now encodes such a value as {"NULL": true}, matching IsNull(), which already reports it as null. Values built by the constructors or by UnmarshalJSON never hold a nil value, so their encoding is unchanged.

Testing

  • Added TestMarshalZeroValue (a zero value, and a map with a zero-valued entry). On main it panics with interface conversion: events.anyValue is nil, not []uint8; with this change it passes.
  • go test ./events/ passes, go vet ./... is clean and golangci-lint run ./events/ reports 0 issues. (TestXRayCausePlumbing in ./lambda fails on my Windows machine on main too, unrelated to this change.)

This change was prepared with AI assistance; I reviewed and tested it.

A zero DynamoDBAttributeValue (an unset field, a missing map key, or a
value left behind by a failed UnmarshalJSON) has dataType 0, which is
DataTypeBinary, and a nil value. MarshalJSON took the Binary branch and
panicked on av.value.([]byte). Encode it as NULL instead, matching
IsNull, which already reports it as null.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.93%. Comparing base (4111853) to head (80aa9ae).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #656      +/-   ##
==========================================
- Coverage   82.04%   81.93%   -0.12%     
==========================================
  Files          37       37              
  Lines        1487     1489       +2     
==========================================
  Hits         1220     1220              
- Misses        264      266       +2     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

events: json.Marshal panics on a zero DynamoDBAttributeValue

2 participants