Skip to content

Conversation

nickng
Copy link
Member

@nickng nickng commented Nov 29, 2022

When using the new Augment function to add context and wrap errors, the error message in Go is chained and displayed with the full chain of context:

err := InternalService("code", "message", nil)
augmentedErr := Augment(err, "context", nil)

// This is "internal_service.code: context: message"
augmentedErr.Error()

But the marshaled error only displays the first level of context, i.e.

// This is just "context"
Marshal(augmentedErr.(*Error)).Message

This commit changes the Marshal behaviour to include the full context chain of error, so it's actually useful outside of Go when marshaled.

// This is now "context: message"
Marshal(augmentedErr.(*Error)).Message

Retryable: nil,
},
},
// Wrapped errors only gets unmarshaled as a single error
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marshaling and unmarshaling are asymmetric to start with, but the error code is preserved.

// these are separate from above because the marshaling and unmarshaling isn't symmetric.

@nickng nickng marked this pull request as ready for review November 29, 2022 12:18
When using the new `Augment` function to add context and wrap errors,
the error message in Go is chained and displayed with the full chain
of context:

```
err := InternalService("code", "message", nil)
augmentedErr := Augment(err, "context", nil)

// This is "internal_service.code: context: message"
augmentedErr.Error()
```

But the marshaled error only displays the first level of context,
i.e.

```
// This is just "context"
Marshal(augmentedErr.(*Error)).Message
```

This commit changes the Marshal behaviour to include the full context
chain of error, so it's actually useful outside of Go when marshaled.

```
// This is now "context: message"
Marshal(augmentedErr.(*Error)).Message
```
@nickng nickng force-pushed the nickng-marshal-full-message branch from ff4c482 to 2472e06 Compare November 29, 2022 12:19
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.

2 participants