{
  "id": "go/missing-import-cycle-with-init",
  "signature": "import cycle not allowed\npackage A\n\timports B\n\timports A",
  "signature_zh": "不允许的导入循环\n包 A\n\t导入 B\n\t导入 A",
  "regex": "import cycle not allowed\\npackage \\w+\\n\\timports \\w+\\n\\timports \\w+",
  "domain": "go",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "Two or more packages import each other directly or indirectly, creating a circular dependency that Go's compiler cannot resolve.",
  "root_cause_type": "generic",
  "root_cause_zh": "两个或多个包直接或间接相互导入，创建了 Go 编译器无法解析的循环依赖。",
  "versions": [
    {
      "version": "go1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using a blank import (_ \"package\") to break the cycle",
      "why_fails": "Blank imports only trigger init() functions, they don't resolve the circular dependency in the type system.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Moving all code into a single package",
      "why_fails": "Violates separation of concerns; makes the codebase monolithic and harder to maintain.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding a new import that re-exports types from the cycle",
      "why_fails": "Creates a longer cycle or introduces a third package that still depends on the cycle.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Extract the shared types or interfaces into a third package that both A and B import",
      "success_rate": 0.9,
      "how": "Extract the shared types or interfaces into a third package that both A and B import",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use dependency injection: pass interfaces from A to B instead of importing A directly in B",
      "success_rate": 0.85,
      "how": "Use dependency injection: pass interfaces from A to B instead of importing A directly in B",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Extract the shared types or interfaces into a third package that both A and B import",
    "Use dependency injection: pass interfaces from A to B instead of importing A directly in B"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/ref/spec#Import_declarations",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-07-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}