{"record":{"id":"f1ffb802f99f00a8","repo":"mastra-ai/mastra","slug":"github-source-control-request-failed-res-status","errorCode":null,"errorMessage":"GitHub source control request failed: ${res.status}","messagePattern":"GitHub source control request failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/providers/github.ts","lineNumber":122,"sourceCode":"    const res = await this.fetch(`${this.endpoint}/v1/server/source-storage/github${path}`, {\n      ...init,\n      headers: {\n        Authorization: `Bearer ${this.token}`,\n        Accept: 'application/json',\n        'Content-Type': 'application/json',\n        ...init?.headers,\n      },\n    });\n\n    if (!res.ok) {\n      let detail = `GitHub source control request failed: ${res.status}`;\n      try {\n        const body = (await res.json()) as BrokerErrorResponse;\n        detail = body.detail ?? detail;\n      } catch {\n        // Ignore non-JSON error bodies.\n      }\n      throw new Error(detail);\n    }\n\n    return (await res.json()) as T;\n  }\n}\n\nexport function createGitHubSourceControlProviderFromEnv(\n  env: Record<string, string | undefined> = process.env,\n  defaults?: { pathPrefix?: string },\n): GitHubSourceControlProvider | undefined {\n  if (env.MASTRA_SOURCE_PROVIDER !== 'github') return undefined;\n\n  const endpoint = env.MASTRA_SOURCE_PROVIDER_ENDPOINT ?? env.MASTRA_SHARED_API_URL ?? env.MASTRA_CLOUD_API_ENDPOINT;\n  const token = env.MASTRA_PLATFORM_ACCESS_TOKEN ?? env.MASTRA_CLOUD_ACCESS_TOKEN;\n\n  if (!endpoint || !token) return undefined;\n\n  return new GitHubSourceControlProvider({","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/providers/github.ts#L104-L140","documentation":"The GitHub storage provider's request helper wraps every HTTP call; when the response status is not OK it extracts a JSON 'detail' if available and throws 'GitHub source control request failed: <status>'. All provider operations (capabilities, file listing, history, change requests) funnel through it, so any GitHub API error surfaces here.","triggerScenarios":"Any API call to GitHub returning a non-2xx status: 401/403 (bad or expired token, missing scopes), 404 (repo/branch/path not found), 422 (bad ref or payload), 429/5xx (rate limit or GitHub outage).","commonSituations":"GITHUB_TOKEN missing scopes (repo/content permissions); token expired or belonging to a revoked app; wrong repo owner/name configured; hitting secondary rate limits during bulk history reads.","solutions":["Inspect the status code and message detail; verify the configured token with `gh auth status` or a GET /user call.","Fix repository configuration (owner/repo/branch) and confirm the token has the required scopes.","Respect rate limits: add backoff/retry on 429 and 5xx, honoring the Retry-After header."],"exampleFix":"// before\nconst files = await githubStorage.files('/'); // throws on 404 silently handled upstream\n// after\ntry {\n  const files = await githubStorage.files('/');\n} catch (e) {\n  if (String(e.message).includes('403')) {\n    console.error('Check GitHub token scopes and rate limits');\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":"// Pre-flight: verify token and repo access\nconst res = await fetch('https://api.github.com/repos/' + owner + '/' + repo, {\n  headers: { Authorization: `Bearer ${token}` }\n});\nif (!res.ok) throw new Error(`GitHub pre-flight failed: ${res.status}`);","typeGuard":null,"tryCatchPattern":"try {\n  const files = await githubStorage.files(path);\n} catch (e) {\n  const m = /failed: (\\d{3})/.exec(String(e.message));\n  if (m && (m[1] === '429' || m[1].startsWith('5'))) {\n    await backoff(); // retry transient failures\n  } else throw e; // 401/403/404 are configuration errors\n}","preventionTips":["Verify token validity and scopes (repo/contents read) before deploying.","Add exponential backoff for 429/5xx and honor Retry-After.","Validate owner/repo/branch configuration at startup with a lightweight API call."],"tags":["network","github","http"],"backgroundTag":"http-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}