{
  "id": "go/grpc-failed-precondition-state",
  "signature": "rpc error: code = FailedPrecondition desc = resource is not in a valid state for this operation",
  "signature_zh": "rpc错误：代码=前置条件失败 描述=资源未处于此操作的有效状态",
  "regex": "rpc\\ error:\\ code\\ =\\ FailedPrecondition\\ desc\\ =\\ resource\\ is\\ not\\ in\\ a\\ valid\\ state\\ for\\ this\\ operation",
  "domain": "go",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "The server rejected the request because the resource (e.g., database record) is in a state that doesn't allow the operation, such as trying to delete an already deleted item.",
  "root_cause_type": "generic",
  "root_cause_zh": "服务器拒绝请求，因为资源（例如数据库记录）处于不允许操作的状态，例如尝试删除已删除的项目。",
  "versions": [
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Retrying the same request immediately.",
      "why_fails": "Resource state hasn't changed; same error.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the error and proceeding with other operations.",
      "why_fails": "May cause data inconsistency; need to handle the state.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check resource state before the RPC and handle accordingly.",
      "success_rate": 0.9,
      "how": "state, _ := client.GetState(ctx, &pb.GetStateRequest{Id: id})\nif state.Status != \"active\" { return errors.New(\"cannot perform operation on inactive resource\") }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a transactional pattern to ensure state validity.",
      "success_rate": 0.85,
      "how": "// Implement optimistic locking with version field\nreq.Version = currentVersion\nresp, err := client.UpdateResource(ctx, req)\nif status.Code(err) == codes.FailedPrecondition { // retry with fresh version }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}