Skip to content

fix(events): correct CodePipelineEventBridge version field types (fixes #552)#626

Open
nghiack7 wants to merge 2 commits intoaws:mainfrom
nghiack7:fix/codepipeline-eventbridge-version-types
Open

fix(events): correct CodePipelineEventBridge version field types (fixes #552)#626
nghiack7 wants to merge 2 commits intoaws:mainfrom
nghiack7:fix/codepipeline-eventbridge-version-types

Conversation

@nghiack7
Copy link
Copy Markdown

@nghiack7 nghiack7 commented May 9, 2026

Summary

Fixes #552UnmarshalTypeError when handling CodePipelineEventBridgeEvent.

The AWS service team confirmed in the issue the correct types for version fields:

Field Previous type Correct type Reason
.version (top-level) string string Already correct
.detail.version int64 json.Number AWS may send 1 or 2.0 (float)
.detail.type.version int64 string AWS sends quoted string e.g. "1"

Why json.Number for detail.version?

AWS sends this field as either an integer (1) or a float (2.0) depending on the pipeline version. Using json.Number preserves the raw value and avoids UnmarshalTypeError for both representations. Callers can use .Int64() or .Float64() to convert as needed.

Breaking change note

This changes public struct field types. Users directly comparing or assigning detail.Version as int64 will need to update their code. However, the previous types caused a hard unmarshal failure at runtime — so the existing types were already broken for real AWS payloads.

Changes

  • events/codepipeline_cloudwatch.go: Fix CodePipelineEventDetail.Version (int64json.Number) and CodePipelineEventDetailType.Version (int64string)
  • events/codepipeline_cloudwatch_test.go: Update expected values; add regression test case for float version payload
  • events/testdata/codepipeline-action-execution-stage-change-event.json: Update type.version from 1 to "1" to match real AWS format
  • events/testdata/codepipeline-action-execution-stage-change-event-float-version.json: New fixture with detail.version: 2.0 to cover the float regression case

Test plan

  • go test ./events/ -run TestUnmarshalCodePipelineEvent passes (4 cases including new float regression)
  • go test ./events/ (full events package) passes with no regressions

Nghĩa Nguyễn Ngọc added 2 commits May 9, 2026 07:41
The AWS service team confirmed the correct types for version fields
in CodePipelineCloudWatchEvent (issue aws#552):

  - .version (top level):     string  -- already correct
  - .detail.version:          numeric -- was int64, now json.Number
  - .detail.type.version:     string  -- was int64, now string

The previous int64 types caused UnmarshalTypeError at runtime when
AWS sent detail.version as a float (e.g. 2.0) or detail.type.version
as a quoted string (e.g. "1").

json.Number is used for detail.version to handle both integer and
float representations without losing the raw value.

Test fixture updated to reflect real AWS payload format, and a new
fixture added to cover the float version regression case.

Fixes aws#552
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.12%. Comparing base (815d21f) to head (e573267).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #626   +/-   ##
=======================================
  Coverage   75.12%   75.12%           
=======================================
  Files          36       36           
  Lines        1419     1419           
=======================================
  Hits         1066     1066           
  Misses        274      274           
  Partials       79       79           

☔ View full report in Codecov by Sentry.
📢 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.

UnmarshalTypeError on CodePipelineEventBridgeEvent

2 participants