Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM-10939 | chore: bump metamodel to v0.0.61 #994

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ model_version:=v0.0.392
model_url:=https://github.com/openshift-online/ocm-api-model.git

# Details of the metamodel to use:
metamodel_version:=v0.0.60
metamodel_version:=v0.0.61

goimports_version:=v0.4.0

Expand Down
47 changes: 47 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/golang/glog"
jsoniter "github.com/json-iterator/go"
Expand All @@ -47,6 +48,7 @@ type ErrorBuilder struct {
reason string
details interface{}
operationID string
timestamp *time.Time
}

// Error represents errors.
Expand All @@ -59,6 +61,7 @@ type Error struct {
reason string
details interface{}
operationID string
timestamp *time.Time
}

// NewError creates a new builder that can then be used to create error objects.
Expand Down Expand Up @@ -115,6 +118,13 @@ func (b *ErrorBuilder) Details(value interface{}) *ErrorBuilder {
return b
}

// Timestamp sets the moment when it happened.
func (b *ErrorBuilder) Timestamp(value *time.Time) *ErrorBuilder {
b.timestamp = value
b.bitmap_ |= 128
return b
}

// Copy copies the attributes of the given error into this
// builder, discarding any previous values.
func (b *ErrorBuilder) Copy(object *Error) *ErrorBuilder {
Expand All @@ -129,6 +139,7 @@ func (b *ErrorBuilder) Copy(object *Error) *ErrorBuilder {
b.reason = object.reason
b.details = object.details
b.operationID = object.operationID
b.timestamp = object.timestamp
return b
}

Expand All @@ -142,6 +153,7 @@ func (b *ErrorBuilder) Build() (result *Error, err error) {
reason: b.reason,
details: b.details,
operationID: b.operationID,
timestamp: b.timestamp,
bitmap_: b.bitmap_,
}
return
Expand Down Expand Up @@ -281,7 +293,26 @@ func (e *Error) GetDetails() (value interface{}, ok bool) {
return
}

// Timestamp sets the moment when it happened
func (e *Error) Timestamp() *time.Time {
if e != nil && e.bitmap_&128 != 0 {
return e.timestamp
}
return nil
}

// GetTimestamp returns the timestamp of the error and a flag
// indicating if the timestamp have a value.
func (e *Error) GetTimestamp() (value *time.Time, ok bool) {
ok = e != nil && e.bitmap_&128 != 0
if ok {
value = e.timestamp
}
return
}

// 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 @@ -293,6 +324,9 @@ func (e *Error) Error() string {
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 Expand Up @@ -372,6 +406,14 @@ func readError(iterator *jsoniter.Iterator) *Error {
case "details":
object.details = iterator.ReadAny().GetInterface()
object.bitmap_ |= 64
case "timestamp":
text := iterator.ReadString()
value, err := time.Parse(time.RFC3339, text)
if err != nil {
iterator.ReportError("", err.Error())
}
object.timestamp = &value
object.bitmap_ |= 128
default:
iterator.ReadAny()
}
Expand Down Expand Up @@ -428,6 +470,11 @@ func writeError(e *Error, stream *jsoniter.Stream) {
stream.WriteObjectField("details")
stream.WriteVal(e.details)
}
if e.bitmap_&128 != 0 {
stream.WriteMore()
stream.WriteObjectField("timestamp")
stream.WriteVal(e.timestamp)
}
stream.WriteObjectEnd()
}

Expand Down
Loading