go data_error ai_generated true

rpc 错误:code = NotFound desc = 资源未找到:订单 998877

rpc error: code = NotFound desc = resource not found: order 998877

ID: go/grpc-not-found-service-method

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2025-02-08首次发现

版本兼容性

版本状态引入弃用备注
1.x active — — —

根因分析

请求的资源在服务器上不存在。NotFound 是合法的应用层响应,但常与 Unimplemented 混淆——后者表示方法本身缺失。

English

The requested resource does not exist on the server. NotFound is a legitimate application-level response, but it is frequently confused with Unimplemented when the method itself is missing.

generic

解决方案

  1. 90% 成功率
    Handle NotFound as a normal application outcome and map it to your domain error:
    
    resp, err := client.GetOrder(ctx, &pb.GetReq{Id: id})
    if status.Code(err) == codes.NotFound {
        return nil, ErrOrderNotFound
    }
  2. 80% 成功率
    When eventual creation is expected, poll with a bounded retry and backoff:
    
    backoff := time.Second
    for i := 0; i < 10; i++ {
        _, err := client.Get(ctx, req)
        if status.Code(err) != codes.NotFound { return err }
        time.Sleep(backoff); backoff *= 2
    }

无效尝试

常见但无效的做法:

  1. 80% 失败

    Without an explicit wait/backoff and an expectation of eventual creation, retrying a NotFound just repeats the same lookup.

  2. 60% 失败

    Many NotFound responses are expected (deleted resources, bad user input); paging on-call for them causes alert fatigue.