Skip to content

Commit e8fd33a

Browse files
authored
Merge pull request #226 from shoriwe/fix/improve-error-context
fix #225: improve error-msg context for unsupported types during interpolation
2 parents e4f129e + d57b6b3 commit e8fd33a

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

interpolate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ func encodeValue(buf []byte, arg interface{}, flavor Flavor) ([]byte, error) {
697697
}
698698

699699
if elem := primative.Type().Elem(); elem.Kind() != reflect.Uint8 {
700-
return nil, ErrInterpolateUnsupportedArgs
700+
return nil, fmt.Errorf("%w: only byte slices are supported", ErrInterpolateUnsupportedArgs)
701701
}
702702

703703
var data []byte
@@ -750,11 +750,11 @@ func encodeValue(buf []byte, arg interface{}, flavor Flavor) ([]byte, error) {
750750
buf = append(buf, "')"...)
751751

752752
default:
753-
return nil, ErrInterpolateUnsupportedArgs
753+
return nil, fmt.Errorf("%w: unsupported flavor for hex number", ErrInterpolateUnsupportedArgs)
754754
}
755755

756756
default:
757-
return nil, ErrInterpolateUnsupportedArgs
757+
return nil, fmt.Errorf("%w: %s", ErrInterpolateUnsupportedArgs, primative.Type().Name())
758758
}
759759
}
760760

interpolate_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"strconv"
8+
"strings"
89
"testing"
910
"time"
1011

@@ -385,7 +386,7 @@ func TestFlavorInterpolate(t *testing.T) {
385386
query, err := c.Flavor.Interpolate(c.SQL, c.Args)
386387

387388
a.Equal(query, c.Query)
388-
a.Assert(err == c.Err || err.Error() == c.Err.Error())
389+
a.Assert(errors.Is(err, c.Err) || strings.Contains(err.Error(), c.Err.Error()))
389390
})
390391
}
391392
}

0 commit comments

Comments
 (0)