I have this error
The error is of type ParseInt. How do I check for this error
I am assuming I would use errors.Is
but not sure how I would do it for this case
CodePudding user response:
https://pkg.go.dev/[email protected]#NumError
type NumError struct {
Func string // the failing function (ParseBool, ParseInt, ParseUint, ParseFloat, ParseComplex)
Num string // the input
Err error // the reason the conversion failed (e.g. ErrRange, ErrSyntax, etc.)
}
The error is of type ParseInt.
"ParseInt"
is the name of the "failing function", the one that returned the error. The actual error type is *strconv.NumError
. You can check for that and the func name like so:
if e, ok := err.(*strconv.NumError); ok && e.Func == "ParseInt" {
// do xyz
}