diff --git a/go.mod b/go.mod index d5d00c4..48ed707 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module sourcecode.social/reiver/go-opt go 1.18 + +require sourcecode.social/reiver/go-erorr v0.0.0-20230922202459-231149d185a1 // indirect diff --git a/go.sum b/go.sum index e69de29..fa79421 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,2 @@ +sourcecode.social/reiver/go-erorr v0.0.0-20230922202459-231149d185a1 h1:wpnz4JicQBLWrgGphYBls7DysIFCcnWgDz/vce/sY8E= +sourcecode.social/reiver/go-erorr v0.0.0-20230922202459-231149d185a1/go.mod h1:NFtd7fzEf0r6A6R7JXYZfayRhPaJy0zt/18VWoLzrxA= diff --git a/optional_marshaljson.go b/optional_marshaljson.go index c2c8111..b802834 100644 --- a/optional_marshaljson.go +++ b/optional_marshaljson.go @@ -1,8 +1,9 @@ package opt import ( - "fmt" "encoding/json" + + "sourcecode.social/reiver/go-erorr" ) var _ json.Marshaler = Nothing[bool]() @@ -14,11 +15,11 @@ func (receiver Optional[T]) MarshalJSON() ([]byte, error) { case bool, string, json.Marshaler: // these are OK. default: - return nil, fmt.Errorf("cannot marshal something of type %T into JSON because parameterized type is ‘%T’ rather than ‘bool’ or ‘string’", receiver, receiver.value) + return nil, erorr.Errorf("opt: cannot marshal something of type %T into JSON because parameterized type is ‘%T’ rather than ‘bool’, ‘string’, or ‘json.Marshaler’", receiver, receiver.value) } if receiver.isnothing() { - return nil, fmt.Errorf("cannot marshal opt.Nothing[%T]() into JSON", receiver.value) + return nil, erorr.Errorf("opt: cannot marshal opt.Nothing[%T]() into JSON", receiver.value) } return json.Marshal(receiver.value) diff --git a/optional_unmarshaljson.go b/optional_unmarshaljson.go index 51e6a1c..7f7c8cd 100644 --- a/optional_unmarshaljson.go +++ b/optional_unmarshaljson.go @@ -1,8 +1,9 @@ package opt import ( - "fmt" "encoding/json" + + "sourcecode.social/reiver/go-erorr" ) var _ json.Unmarshaler = new(Optional[bool]) @@ -14,7 +15,7 @@ func (receiver *Optional[T]) UnmarshalJSON(data []byte) error { case *bool, *string, json.Unmarshaler: // these are OK. default: - return fmt.Errorf("cannot unmarshal into something of type %T from JSON because pointer to parameterized type is ‘%T’ rather than ‘*bool’, ‘*string’, or ‘json.Unmarshaler’", receiver, &receiver.value) + return erorr.Errorf("opt: cannot unmarshal into something of type %T from JSON because pointer to parameterized type is ‘%T’ rather than ‘*bool’, ‘*string’, or ‘json.Unmarshaler’", receiver, &receiver.value) } {