> For the complete documentation index, see [llms.txt](https://linde.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://linde.gitbook.io/blog/grpc-de-go-shi-xian-qi-fan-hui-de-error-wei-shen-me-bu-yong-fmt.errorf.md).

# gRPC的Go实现，其返回的error为什么不用fmt.Errorf()？

比如你要返回一个gorm.ErrRecordNotFound，那么gRPC的调用者最终收到的error的信息会是这样：

```
rpc error: code = Unknown desc = 
```

调用者想这么判断error：

```
if errors.Is(err, gorm.ErrRecordNotFound)
```

会返回false

用errors.As也不行

```
errors.As(err, &gorm.ErrRecordNotFound)
```

在运行测试的时候会报错：second argument to errors.As should not be \*error

GPT的解释：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.

{% embed url="<https://github.com/grpc/grpc-go/issues/2934>" %}
