Skip to content

Commit

Permalink
OCM-10939 | fix: adjust error message to include timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbranco committed Sep 6, 2024
1 parent 099dd4b commit 02987f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/generators/golang/errors_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ func (g *ErrorsGenerator) generateCommonErrors() error {
}
// Error is the implementation of the error interface.
// Details are intentionally left out as there is no guarantee of their type
func (e *Error) Error() string {
chunks := make([]string, 0, 3)
if e.bitmap_&1 != 0 {
Expand All @@ -471,6 +472,9 @@ func (g *ErrorsGenerator) generateCommonErrors() error {
if e.bitmap_&8 != 0 {
chunks = append(chunks, fmt.Sprintf("code is '%s'", e.code))
}
if e.bitmap_&128 != 0 {
chunks = append(chunks, fmt.Sprintf("at '%v'", e.timestamp.Format(time.RFC3339)))
}
if e.bitmap_&32 != 0 {
chunks = append(chunks, fmt.Sprintf("operation identifier is '%s'", e.operationID))
}
Expand Down
6 changes: 6 additions & 0 deletions tests/go/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ var _ = Describe("Marshal", func() {
"details": {"kind" : "cluster error"},
"timestamp": "%v"
}`, now.Format(time.RFC3339Nano))))
Expect(object.Error()).To(Equal(
fmt.Sprintf(
"identifier is '401', code is 'CLUSTERS-MGMT-401', at '%v' and operation identifier is '456': My reason",
now.Format(time.RFC3339))))
})

It("Can write an error without timestamp", func() {
Expand All @@ -223,6 +227,8 @@ var _ = Describe("Marshal", func() {
"operation_id": "456",
"details": {"kind" : "cluster error"}
}`))
Expect(object.Error()).To(Equal(
"identifier is '401', code is 'CLUSTERS-MGMT-401' and operation identifier is '456': My reason"))
})

It("Can write empty list of booleans", func() {
Expand Down

0 comments on commit 02987f1

Please sign in to comment.