From 02987f1a0b6d572f8859eef99508608c0b16657b Mon Sep 17 00:00:00 2001 From: Guilherme Branco Date: Fri, 6 Sep 2024 16:08:51 -0300 Subject: [PATCH] OCM-10939 | fix: adjust error message to include timestamp --- pkg/generators/golang/errors_generator.go | 4 ++++ tests/go/marshal_test.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/pkg/generators/golang/errors_generator.go b/pkg/generators/golang/errors_generator.go index 8155e61..a88ecaf 100644 --- a/pkg/generators/golang/errors_generator.go +++ b/pkg/generators/golang/errors_generator.go @@ -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 { @@ -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)) } diff --git a/tests/go/marshal_test.go b/tests/go/marshal_test.go index 682fa91..06f9e79 100644 --- a/tests/go/marshal_test.go +++ b/tests/go/marshal_test.go @@ -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() { @@ -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() {