forked from rosa/hakurei
+6
-5
@@ -7,7 +7,8 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// decodeJSON decodes json from r and stores it in v. A non-nil error results in a call to fatal.
|
||||
// decodeJSON decodes json from r and stores it in v. A non-nil error results in
|
||||
// a call to fatal.
|
||||
func decodeJSON(fatal func(v ...any), op string, r io.Reader, v any) {
|
||||
err := json.NewDecoder(r).Decode(v)
|
||||
if err == nil {
|
||||
@@ -47,14 +48,14 @@ func encodeJSON(fatal func(v ...any), output io.Writer, short bool, v any) {
|
||||
}
|
||||
|
||||
if err := encoder.Encode(v); err != nil {
|
||||
var marshalerError *json.MarshalerError
|
||||
if errors.As(err, &marshalerError) && marshalerError != nil {
|
||||
if e, ok := errors.AsType[*json.MarshalerError](err); ok && e != nil {
|
||||
// this likely indicates an implementation error in hst
|
||||
fatal("cannot encode json for " + marshalerError.Type.String() + ": " + marshalerError.Err.Error())
|
||||
fatal("cannot encode json for " + e.Type.String() + ": " + e.Err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// UnsupportedTypeError, UnsupportedValueError: incorrect usage, does not need to be handled
|
||||
// UnsupportedTypeError, UnsupportedValueError: incorrect usage, does
|
||||
// not need to be handled
|
||||
fatal("cannot write json: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user