{"record":{"id":"6f85bd6bb766d787","repo":"Panniantong/Agent-Reach","slug":"gh-hosts-yml-github-com","errorCode":null,"errorMessage":"gh hosts.yml 的 github.com 配置无效","messagePattern":"gh hosts\\.yml 的 github\\.com 配置无效","errorType":"exception","errorClass":"GitHubConfigError","httpStatus":null,"severity":"error","filePath":"agent_reach/channels/github.py","lineNumber":76,"sourceCode":"        )\n    except (OSError, PrivatePathError, UnicodeError) as exc:\n        raise GitHubConfigError(\"gh hosts.yml 无法安全读取\") from exc\n    if raw is None:\n        return False\n    try:\n        payload = yaml.safe_load(raw)\n    except yaml.YAMLError as exc:\n        raise GitHubConfigError(\"gh hosts.yml 不是有效的 UTF-8 YAML\") from exc\n    if payload is None:\n        return False\n    if not isinstance(payload, dict):\n        raise GitHubConfigError(\"gh hosts.yml 顶层必须是对象\")\n\n    host = payload.get(\"github.com\")\n    if host is None:\n        return False\n    if not isinstance(host, dict):\n        raise GitHubConfigError(\"gh hosts.yml 的 github.com 配置无效\")\n\n    users = host.get(\"users\")\n    if users is not None and not isinstance(users, dict):\n        raise GitHubConfigError(\"gh hosts.yml 的 users 配置无效\")\n    return bool(host.get(\"oauth_token\") or host.get(\"user\") or users)\n\n\ndef _explicit_github_credentials(config) -> bool:\n    if any(os.environ.get(name) for name in (\"GH_TOKEN\", \"GITHUB_TOKEN\")):\n        return True\n    if config is None:\n        return False\n    try:\n        return bool(config.get(\"github_token\"))\n    except Exception as exc:\n        raise GitHubConfigError(\"Agent Reach 的 GitHub 配置无法读取\") from exc\n\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/Panniantong/Agent-Reach/blob/93ae1d18c37b707dec053c7c4f9d91cd8ef8943d/agent_reach/channels/github.py#L58-L94","documentation":"Raised when the top-level 'github.com' key exists in hosts.yml but its value is not a mapping (scalar, list, or None-shape mismatch). The per-host entry must be a dict holding keys like oauth_token, user, users.","triggerScenarios":"hosts.yml has 'github.com: some string' or 'github.com: [a, b]'. payload.get('github.com') returns a non-dict, isinstance check fails, error raised. A missing 'github.com' key returns False quietly (no error).","commonSituations":"Hand-editing that flattens the structure; YAML anchor reuse producing a list of hosts; template systems writing 'github.com: {{ token }}' with the placeholder unexpanded.","solutions":["Fix the github.com entry to a nested mapping: 'github.com:\\n  oauth_token: ...\\n  user: ...'","Run `gh auth status` — if it also complains, re-login with `gh auth login`","Validate locally: python -c \"import yaml; d=yaml.safe_load(open('$HOME/.config/gh/hosts.yml')); assert isinstance(d['github.com'], dict)\""],"exampleFix":"# before\n github.com: gho_abc123\n# after\n github.com:\n   oauth_token: gho_abc123\n   user: myname","handlingStrategy":"validation","validationCode":"import yaml\n\ndef github_entry_valid(path) -> bool:\n    try:\n        d = yaml.safe_load(open(path, encoding=\"utf-8\").read()) or {}\n    except Exception:\n        return False\n    host = d.get(\"github.com\")\n    return host is None or isinstance(host, dict)","typeGuard":null,"tryCatchPattern":"except GitHubConfigError as exc:\n    if \"github.com 配置无效\" in str(exc):\n        hint = \"rewrite the github.com block as a nested mapping or re-run gh auth login\"","preventionTips":["Per-host values in hosts.yml are always nested mappings","Validate with gh auth status after editing","Avoid YAML flow lists for host entries"],"tags":["github","gh-cli","yaml","config"],"backgroundTag":null,"analyzedSha":"93ae1d18c37b707dec053c7c4f9d91cd8ef8943d","analyzedAt":"2026-08-14T22:54:06.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}