From 8cfabdcc163ab36dc3a5b5b6844b7fb9844975e2 Mon Sep 17 00:00:00 2001 From: Adam Talbot Date: Tue, 6 Feb 2024 13:01:58 +0000 Subject: [PATCH] fix: wrap errors returned by JSON unmarshal Currently `%v` is used inside an `Errorf` call, this means the original errors is lost and cannot be unwrapped to. By changing it to `%w` the error is preserved and can be retrieved with `errors.As`. --- yaml.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yaml.go b/yaml.go index fc10246..54c1821 100644 --- a/yaml.go +++ b/yaml.go @@ -92,7 +92,7 @@ func jsonUnmarshal(reader io.Reader, obj interface{}, opts ...JSONOpt) error { d = opt(d) } if err := d.Decode(&obj); err != nil { - return fmt.Errorf("while decoding JSON: %v", err) + return fmt.Errorf("while decoding JSON: %w", err) } return nil }