gRPC's Go implementation: why doesn't its returned error use fmt.Errorf()?

For example, if you want to return a gorm.ErrRecordNotFound, then the error information the gRPC caller ultimately receives will look like this:

rpc error: code = Unknown desc = 

The caller wants to judge the error like this:

if errors.Is(err, gorm.ErrRecordNotFound)

will return false

Using errors.As also doesn't work

errors.As(err, &gorm.ErrRecordNotFound)

When running tests it will report an error: second argument to errors.As should not be *error

GPT's explanation: The error message you're seeing is because errors.As expects a pointer to an interface as its second argument. However, gorm.ErrRecordNotFound is a value of type error, not an interface type.

Last updated