{"record":{"id":"ae368f9cf2ddaf6d","repo":"badges/shields","slug":"not-a-regular-file","errorCode":null,"errorMessage":"not a regular file","messagePattern":"not a regular file","errorType":"exception","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"services/github/github-size.service.js","lineNumber":67,"sourceCode":"      return this._requestJson({\n        url: `/repos/${user}/${repo}/contents/${path}?ref=${branch}`,\n        schema,\n        httpErrors: httpErrorsFor('repo, branch or file not found'),\n      })\n    } else {\n      return this._requestJson({\n        url: `/repos/${user}/${repo}/contents/${path}`,\n        schema,\n        httpErrors: httpErrorsFor('repo or file not found'),\n      })\n    }\n  }\n\n  async handle({ user, repo, path }, queryParams) {\n    const branch = queryParams.branch\n    const body = await this.fetch({ user, repo, path, branch })\n    if (Array.isArray(body)) {\n      throw new NotFound({ prettyMessage: 'not a regular file' })\n    }\n    return renderSizeBadge(body.size, 'iec')\n  }\n}\n","sourceCodeStart":49,"sourceCodeEnd":72,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/github/github-size.service.js#L49-L72","documentation":"The GitHub size service fetches metadata for a repository path and renders its file size. The GitHub contents API returns an array when the path is a directory, so the service uses `Array.isArray(body)` to detect directories and throws `NotFound` with 'not a regular file'. Only single-file paths can be sized.","triggerScenarios":"Requesting a size badge with a `path` that resolves to a directory (GitHub returns a JSON array of contents entries) instead of a single file; empty directory also yields an array.","commonSituations":"Path typo pointing at a folder; user forgets to include the filename in the path; path points at repo root; intended file was replaced by a directory of the same conceptual name.","solutions":["Include the full file path (with filename) in the badge URL, e.g. path=src/index.js not path=src","Verify on GitHub that the path is a regular file, not a directory","Correct typos in the path parameter"],"exampleFix":"// before\n/badge/size/user/repo/src   -> not a regular file\n// after\n/badge/size/user/repo/src/index.js","handlingStrategy":"type-guard","validationCode":"const res = await fetch(`https://api.github.com/repos/${user}/${repo}/contents/${path}`)\nconst body = await res.json()\nif (Array.isArray(body)) throw new Error(`${path} is a directory, not a file`)","typeGuard":"const isFileEntry = (body) => body != null && !Array.isArray(body) && body.type === 'file'","tryCatchPattern":"try {\n  await fetchSizeBadge(user, repo, path)\n} catch (e) {\n  if (e.message === 'not a regular file') return 'n/a'\n  throw e\n}","preventionTips":["Always include the filename in the `path` parameter, never just a directory","Check the path on GitHub resolves to a file (type: file) before using the badge","Watch for directories replacing files at the same path"],"tags":["github","not-found","wrong-argument-type"],"backgroundTag":"path-is-not-a-file","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}