{"record":{"id":"942602608306bcf1","repo":"badges/shields","slug":"not-a-directory","errorCode":null,"errorMessage":"not a directory","messagePattern":"not a directory","errorType":"validation","errorClass":"InvalidParameter","httpStatus":400,"severity":"error","filePath":"services/github/github-directory-file-count.service.js","lineNumber":125,"sourceCode":"              ... on Tree {\n                entries {\n                  type\n                  extension\n                }\n              }\n            }\n          }\n        }\n      `,\n      variables: { user, repo, expression },\n      schema,\n      transformErrors,\n    })\n  }\n\n  static transform(files, { type, extension }) {\n    if (!Array.isArray(files)) {\n      throw new InvalidParameter({ prettyMessage: 'not a directory' })\n    }\n\n    if (type !== 'file' && extension) {\n      throw new InvalidParameter({\n        prettyMessage: 'extension is applicable for type file only',\n      })\n    }\n\n    if (type) {\n      const objectType = type === 'dir' ? 'tree' : 'blob'\n      files = files.filter(file => file.type === objectType)\n    }\n\n    if (extension) {\n      files = files.filter(file => file.extension === `.${extension}`)\n    }\n\n    return {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/github/github-directory-file-count.service.js#L107-L143","documentation":"github-directory-file-count's static transform() expects the fetched content to be an array of directory entries. If `files` is not an Array (the GraphQL object was not a tree — e.g. it's a blob or null entries), it throws InvalidParameter 'not a directory'. The requested path exists but isn't a directory, so a file count is meaningless.","triggerScenarios":"Requesting a directory file count where the `path` param points at a file (blob) instead of a folder — the API returns a single object rather than an entries array, which fails the Array.isArray check.","commonSituations":"Typos in badge URLs pointing at a file like README.md; path pointing to repo root with an incorrect `dir` value; repos where the documented folder was replaced by a single file.","solutions":["Point the `path` parameter at a directory, not a file (drop README.md-style paths).","Omit `path` entirely to count files in the repository root.","Verify the path exists as a folder on GitHub (it should render as a directory listing)."],"exampleFix":"// before\n/service/github/directory-file-count/user/repo/src/index.js.json\n// after\n/service/github/directory-file-count/user/repo/src.json","handlingStrategy":"validation","validationCode":"// confirm path is a directory via the contents API\nconst meta = await fetch('https://api.github.com/repos/OWNER/REPO/contents/' + path).then(r => r.json());\nif (!Array.isArray(meta)) throw new Error('path is not a directory');","typeGuard":"function isDirectoryListing(entries) {\n  return Array.isArray(entries) && entries.every(e => e != null && typeof e.path === 'string' && typeof e.type === 'string');\n}","tryCatchPattern":"try {\n  const { count } = await getDirectoryFileCount({ user, repo, path });\n} catch (e) {\n  if (e.prettyMessage === 'not a directory') {\n    // fix the path param to point at a folder\n  } else throw e;\n}","preventionTips":["Point the path param at folders, never individual files.","Omit path to count the repository root.","Re-check badge paths after restructuring the repo."],"tags":["github","invalid-parameter","directory","path"],"backgroundTag":"not-a-directory","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}