{"record":{"id":"16e178de8cf793df","repo":"anuraghazra/github-readme-stats","slug":"unexpected-behavior","errorCode":null,"errorMessage":"Unexpected behavior","messagePattern":"Unexpected behavior","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/fetchers/repo.js","lineNumber":114,"sourceCode":"      ...data.user.repository,\n      starCount: data.user.repository.stargazers.totalCount,\n    };\n  }\n\n  if (isOrg) {\n    if (\n      !data.organization.repository ||\n      data.organization.repository.isPrivate\n    ) {\n      throw new Error(\"Organization Repository Not found\");\n    }\n    return {\n      ...data.organization.repository,\n      starCount: data.organization.repository.stargazers.totalCount,\n    };\n  }\n\n  throw new Error(\"Unexpected behavior\");\n};\n\nexport { fetchRepo };\nexport default fetchRepo;\n","sourceCodeStart":96,"sourceCodeEnd":119,"githubUrl":"https://github.com/anuraghazra/github-readme-stats/blob/54a7985aeefda00d5eadb55b80c17c7f976c37d2/src/fetchers/repo.js#L96-L119","documentation":"Defensive 'should never happen' Error at the end of fetchRepo. It is reached only if neither isUser (data.organization === null && data.user) nor isOrg (data.user === null && data.organization) is true, despite passing the earlier !data.user && !data.organization check. Concretely this requires data.user and data.organization to BOTH be non-null, or both non-null-but-falsy in an unexpected way — the GraphQL getRepo query is not expected to populate both.","triggerScenarios":"A GitHub GraphQL API schema/behavior change that returns both user and organization non-null for the same login; or response mutation upstream (e.g. a custom fetcher/caching layer) that synthesizes a shape the code does not handle. Under normal GitHub behavior this branch is unreachable.","commonSituations":"Essentially never in production. If seen, it indicates either a GitHub API contract change or an interceptor (proxy/monkeypatch) altering the response shape. Treat as a bug report trigger rather than a user-fixable config issue.","solutions":["Log the raw res.data to inspect the actual user/organization values GitHub returned.","Check for any response-rewriting middleware, cache, or fetcher override in the deployment.","Open an issue upstream — the GraphQL getRepo contract has changed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Defensive: log the unexpected shape and degrade gracefully rather than crash.\ntry {\n  return await fetchRepo(username, repo);\n} catch (err) {\n  if (err.message === \"Unexpected behavior\") {\n  console.error(\"fetchRepo: both user and organization non-null for\", username);\n    return null;\n  }\n  throw err;\n}","preventionTips":["Treat this error as a bug report: capture the full res.data for the maintainer.","Avoid response-rewriting proxies/caches in front of the GraphQL call that could synthesize a both-non-null shape."],"tags":["repo-card","defensive","unreachable","github-api","schema"],"backgroundTag":null,"analyzedSha":"54a7985aeefda00d5eadb55b80c17c7f976c37d2","analyzedAt":"2026-08-12T23:20:41.776Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}