package jsonkit // DecodeError wraps an underlying decode error with optional diagnostics. type DecodeError struct { err error diagnostics []Diagnostic } // Error implements error. func (e *DecodeError) Error() string { if e == nil || e.err == nil { return "" } return e.err.Error() } // Unwrap returns the underlying decode error. func (e *DecodeError) Unwrap() error { if e == nil { return nil } return e.err } // Diagnostics returns a copy of attached diagnostics. func (e *DecodeError) Diagnostics() []Diagnostic { if e == nil { return nil } out := make([]Diagnostic, len(e.diagnostics)) copy(out, e.diagnostics) return out } func wrapDecodeError(err error, res DecodeResult) error { if err == nil { return nil } diags := res.Diagnostics() if len(diags) == 0 { return err } return &DecodeError{ err: err, diagnostics: diags, } }