badges/shields · error · InvalidParameter
not a directory
Error message
not a directory
What it means
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.
Source
Thrown at services/github/github-directory-file-count.service.js:125
... on Tree {
entries {
type
extension
}
}
}
}
}
`,
variables: { user, repo, expression },
schema,
transformErrors,
})
}
static transform(files, { type, extension }) {
if (!Array.isArray(files)) {
throw new InvalidParameter({ prettyMessage: 'not a directory' })
}
if (type !== 'file' && extension) {
throw new InvalidParameter({
prettyMessage: 'extension is applicable for type file only',
})
}
if (type) {
const objectType = type === 'dir' ? 'tree' : 'blob'
files = files.filter(file => file.type === objectType)
}
if (extension) {
files = files.filter(file => file.extension === `.${extension}`)
}
return {View on GitHub (pinned to 766fd8bc89)
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).
Example fix
// before /service/github/directory-file-count/user/repo/src/index.js.json // after /service/github/directory-file-count/user/repo/src.json
Defensive patterns
Strategy: validation
Validate before calling
// confirm path is a directory via the contents API
const meta = await fetch('https://api.github.com/repos/OWNER/REPO/contents/' + path).then(r => r.json());
if (!Array.isArray(meta)) throw new Error('path is not a directory'); Type guard
function isDirectoryListing(entries) {
return Array.isArray(entries) && entries.every(e => e != null && typeof e.path === 'string' && typeof e.type === 'string');
} Try / catch
try {
const { count } = await getDirectoryFileCount({ user, repo, path });
} catch (e) {
if (e.prettyMessage === 'not a directory') {
// fix the path param to point at a folder
} else throw e;
} Prevention
- Point the path param at folders, never individual files.
- Omit path to count the repository root.
- Re-check badge paths after restructuring the repo.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- directory not found
- no common ancestor
- extension is applicable for type file only
- strict ssl is required
- invalid url parameter
AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30).
Data as JSON: /api/errors/942602608306bcf1.
Report an issue: GitHub.