Merge pull request #226 from shoriwe/fix/improve-error-context

fix #225: improve error-msg context for unsupported types during interpolation
This commit is contained in:
Huan Du
2025-12-29 10:44:45 +08:00
committed by GitHub
2 changed files with 5 additions and 4 deletions
+3 -3
View File
@@ -697,7 +697,7 @@ func encodeValue(buf []byte, arg interface{}, flavor Flavor) ([]byte, error) {
}
if elem := primative.Type().Elem(); elem.Kind() != reflect.Uint8 {
return nil, ErrInterpolateUnsupportedArgs
return nil, fmt.Errorf("%w: only byte slices are supported", ErrInterpolateUnsupportedArgs)
}
var data []byte
@@ -750,11 +750,11 @@ func encodeValue(buf []byte, arg interface{}, flavor Flavor) ([]byte, error) {
buf = append(buf, "')"...)
default:
return nil, ErrInterpolateUnsupportedArgs
return nil, fmt.Errorf("%w: unsupported flavor for hex number", ErrInterpolateUnsupportedArgs)
}
default:
return nil, ErrInterpolateUnsupportedArgs
return nil, fmt.Errorf("%w: %s", ErrInterpolateUnsupportedArgs, primative.Type().Name())
}
}
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"
"testing"
"time"
@@ -385,7 +386,7 @@ func TestFlavorInterpolate(t *testing.T) {
query, err := c.Flavor.Interpolate(c.SQL, c.Args)
a.Equal(query, c.Query)
a.Assert(err == c.Err || err.Error() == c.Err.Error())
a.Assert(errors.Is(err, c.Err) || strings.Contains(err.Error(), c.Err.Error()))
})
}
}