{"record":{"id":"3fdff0449b372038","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-sync-github-file-content-reason","errorCode":null,"errorMessage":"Failed to sync GitHub file content. ${reason}","messagePattern":"Failed to sync GitHub file content\\. (.+?)","errorType":"exception","errorClass":"Error","httpStatus":200,"severity":"error","filePath":"collector/extensions/resync/index.js","lineNumber":111,"sourceCode":" */\nasync function resyncGithub({ chunkSource }, response) {\n  if (!chunkSource) throw new Error(\"Invalid source property provided\");\n  try {\n    // Github file data is `payload` encrypted (might contain PAT). So we need to expand its\n    // encrypted payload back into query params so we can reFetch the page with same access token/params.\n    const source = response.locals.encryptionWorker.expandPayload(chunkSource);\n    const {\n      fetchGithubFile,\n    } = require(\"../../utils/extensions/RepoLoader/GithubRepo\");\n    const { success, reason, content } = await fetchGithubFile({\n      repoUrl: `https:${source.pathname}`, // need to add back the real protocol\n      branch: source.searchParams.get(\"branch\"),\n      accessToken: source.searchParams.get(\"pat\"),\n      sourceFilePath: source.searchParams.get(\"path\"),\n    });\n\n    if (!success)\n      throw new Error(`Failed to sync GitHub file content. ${reason}`);\n    response.status(200).json({ success, content });\n  } catch (e) {\n    console.error(e);\n    response.status(200).json({\n      success: false,\n      content: null,\n    });\n  }\n}\n\n/**\n * Fetches the content of a specific GitLab file via its chunkSource.\n * Returns the content as a text string of the file in question and only that file.\n * @param {object} data - metadata from document (eg: chunkSource)\n * @param {import(\"../../middleware/setDataSigner\").ResponseWithSigner} response\n */\nasync function resyncGitlab({ chunkSource }, response) {\n  if (!chunkSource) throw new Error(\"Invalid source property provided\");","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/extensions/resync/index.js#L93-L129","documentation":"Thrown by resyncGithub in collector/extensions/resync/index.js:111 when fetchGithubFile(...) from collector/utils/extensions/RepoLoader/GithubRepo resolves with success:false. Inputs come from decrypting chunkSource — repoUrl, branch, accessToken (pat), sourceFilePath. The interpolated `reason` carries the upstream cause. Handler catches and answers HTTP 200 with success:false, content:null.","triggerScenarios":"PAT expired/revoked or lacks read on the repo; file moved or deleted on the branch; branch was renamed/deleted; private repo with no token; GitHub API rate limit (60/hr unauthenticated); repo transferred to another owner.","commonSituations":"Personal Access Token rotated since original scrape; file path changed in a refactor; repo transferred/renamed; classic PAT scoped to a different repo.","solutions":["Check `reason` for the GitHub HTTP status (401/403/404).","Re-scrape the GitHub file with a valid PAT that has `repo` scope (or fine-grained read on the repo) to mint a fresh chunkSource.","Verify the branch still exists and the file path is current.","Confirm the collector's egress to api.github.com (or the GH enterprise host) is allowed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await resyncGithub({ chunkSource }, response); }\ncatch (e) {\n  if (e.message.startsWith(\"Failed to sync GitHub file content.\")) {\n    const upstream = e.message.replace(\"Failed to sync GitHub file content. \", \"\");\n    if (/401|403|bad credentials/i.test(upstream)) rotateGitHubPat();\n    else if (/404/i.test(upstream)) markFileMovedOrDeleted();\n    else if (/rate limit/i.test(upstream)) backoffAndRetry();\n    else scheduleRetry();\n  }\n}","preventionTips":["Use a PAT with the minimum scope needed and rotate it before expiry.","Re-scrape to mint a new chunkSource whenever the PAT changes — old payloads carry the old token.","Watch for 404 — file moves are common in active repos."],"tags":["auth","network","resync","github"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}