Skip to content

fix: add ok check for CustomEventMapKey in NewFromJsonBytesContext#128

Merged
afrittoli merged 2 commits into
mainfrom
worktree-fix-custom-event-ok-check
Apr 8, 2026
Merged

fix: add ok check for CustomEventMapKey in NewFromJsonBytesContext#128
afrittoli merged 2 commits into
mainfrom
worktree-fix-custom-event-ok-check

Conversation

@afrittoli
Copy link
Copy Markdown
Member

Summary

  • The custom event path in NewFromJsonBytesContext did a map lookup on CustomEventMapKey without checking the ok flag
  • If the key was absent, receiver would be the nil zero value for CDEventType
  • A subsequent reflect.TypeOf(receiver).Elem() (or json.Unmarshal) would then panic
  • Added the same guard used for the non-custom path: return a descriptive error instead

Test plan

  • Existing tests pass (go test -tags testonly ./pkg/api/)
  • No panic when a cdeventsMap without CustomEventMapKey receives a custom event

🤖 Generated with Claude Code

The custom event path was doing a map lookup without checking the ok
flag, leaving receiver as the zero value (nil) if CustomEventMapKey
was absent. A subsequent reflect.TypeOf(receiver).Elem() would then
panic. Add the same guard used for non-custom events.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Andrea Frittoli <andrea.frittoli@uk.ibm.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.12%. Comparing base (3cf5657) to head (59e6ab2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #128   +/-   ##
=======================================
  Coverage   85.12%   85.12%           
=======================================
  Files         149      149           
  Lines       13095    13097    +2     
=======================================
+ Hits        11147    11149    +2     
  Misses       1631     1631           
  Partials      317      317           
Files with missing lines Coverage Δ
pkg/api/bindings.go 83.17% <100.00%> (+0.32%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add a test and fixture to exercise the new error returned when a custom
event type is parsed with a cdeventsMap that does not contain
CustomEventMapKey, ensuring the new branch is covered.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Andrea Frittoli <andrea.frittoli@uk.ibm.com>
@afrittoli afrittoli added this pull request to the merge queue Apr 8, 2026
Merged via the queue into main with commit 9a15314 Apr 8, 2026
8 checks passed
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