go data_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2025-02-08First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.x active — — —

Root Cause

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

中文

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

Workarounds

  1. 90% success
    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% success
    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
    }

Dead Ends

Common approaches that don't work:

  1. 80% fail

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

  2. 60% fail

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