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

Add remoteObjectParseError #1134

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion common/remote_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ func multierror(err error, errs ...error) error {
return me
}

type remoteObjectParseError struct {
error
typ string
subType string
val string
}

// Error returns a string representation of the error.
func (e *remoteObjectParseError) Error() string {
return fmt.Sprintf("parsing remote object with type: %s subtype: %s val: %s err: %s",
e.typ, e.subType, e.val, e.error.Error())
}

// Unwrap returns the wrapped parsing error.
func (e *remoteObjectParseError) Unwrap() error {
return e.error
}

func parseRemoteObjectPreview(op *cdpruntime.ObjectPreview) (map[string]any, error) {
obj := make(map[string]any)
var result error
Expand Down Expand Up @@ -142,7 +160,12 @@ func parseRemoteObjectValue(

var v any
if err := json.Unmarshal([]byte(val), &v); err != nil {
return nil, err
return nil, &remoteObjectParseError{
error: err,
typ: string(t),
subType: string(st),
val: val,
}
}

return v, nil
Expand Down