Always make fatal errors json-serializable (#14396)

This commit is contained in:
andig 2024-06-16 16:58:31 +02:00 • committed by GitHub
parent a8f95ef6d0
commit 4d6109d3ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 16 deletions

View file

@ -28,6 +28,27 @@ const (
ClassSponsorship
)
// FatalError is an error that can be marshaled
type FatalError struct {
err error
}
func (e *FatalError) Error() string {
return e.err.Error()
}
func (e FatalError) MarshalJSON() ([]byte, error) {
if je, ok := e.err.(json.Marshaler); ok {
return je.MarshalJSON()
}
return json.Marshal(struct {
Error string `json:"error"`
}{
Error: e.err.Error(),
})
}
// DeviceError indicates the specific device that failed
type DeviceError struct {
Name string