From 852ec7e207a47be873cf1c31801650cd78c752f4 Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Fri, 6 Oct 2023 18:20:32 +0300 Subject: [PATCH] doc: clarify crud error process decoding It is a bit confusing for non-experienced vmihailenco/msgpack users than `nil` values are actually parsed by `DecodeMapLen`, `DecodeUint64` and `DecodeBool` methods to some default value. So I decided to leave a note here. --- crud/result.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crud/result.go b/crud/result.go index cc875a5de..7ae00e68f 100644 --- a/crud/result.go +++ b/crud/result.go @@ -79,6 +79,9 @@ func (r *Result) DecodeMsgpack(d *msgpack.Decoder) error { return fmt.Errorf("unexpected empty response array") } + // DecodeMapLen processes `nil` as zero length map, + // so in `return nil, err` case we don't miss error info. + // https://github.com/vmihailenco/msgpack/blob/3f7bd806fea698e7a9fe80979aa3512dea0a7368/decode_map.go#L79-L81 l, err := d.DecodeMapLen() if err != nil { return err @@ -184,6 +187,9 @@ func (r *NumberResult) DecodeMsgpack(d *msgpack.Decoder) error { return fmt.Errorf("unexpected empty response array") } + // DecodeUint64 processes `nil` as `0`, + // so in `return nil, err` case we don't miss error info. + // https://github.com/vmihailenco/msgpack/blob/3f7bd806fea698e7a9fe80979aa3512dea0a7368/decode_number.go#L91-L93 if r.Value, err = d.DecodeUint64(); err != nil { return err } @@ -225,6 +231,9 @@ func (r *BoolResult) DecodeMsgpack(d *msgpack.Decoder) error { return fmt.Errorf("unexpected empty response array") } + // DecodeBool processes `nil` as `false`, + // so in `return nil, err` case we don't miss error info. + // https://github.com/vmihailenco/msgpack/blob/3f7bd806fea698e7a9fe80979aa3512dea0a7368/decode.go#L367-L369 if r.Value, err = d.DecodeBool(); err != nil { return err }