badges/shields · error · InvalidParameter
directory not found
Error message
directory not found
What it means
handle() fetches the directory via GraphQL and throws InvalidParameter 'directory not found' when `repository.object` is null. GitHub resolved the user/repo but the requested path/ref does not match any object, so the directory cannot be found. Unlike error 105 this means the path doesn't exist at all, rather than existing as a file.
Source
Thrown at services/github/github-directory-file-count.service.js:151
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 {
count: files.length,
}
}
async handle({ user, repo, path }, { type, extension }) {
const json = await this.fetch({ user, repo, path })
if (json.data.repository.object === null) {
throw new InvalidParameter({
prettyMessage: 'directory not found',
})
}
const content = json.data.repository.object.entries
const { count } = this.constructor.transform(content, { type, extension })
return this.constructor.render({ count })
}
}
View on GitHub (pinned to 766fd8bc89)
Solutions
- Verify the folder exists at that exact path on the requested branch (browse it on github.com).
- Update the badge path after repository restructures/renames.
- Check for case mismatches — GitHub paths are case-sensitive.
Example fix
// before /service/github/directory-file-count/user/repo/lib.json (repo uses src/) // after /service/github/directory-file-count/user/repo/src.json
Defensive patterns
Strategy: validation
Validate before calling
// confirm directory exists on the target branch
const res = await fetch(`https://api.github.com/repos/OWNER/REPO/contents/${path}?ref=${branch}`);
if (res.status === 404) throw new Error(`directory '${path}' not found on branch '${branch}'`); Type guard
function isNonNullObject(obj) {
return obj != null && typeof obj === 'object' && ('entries' in obj ? Array.isArray(obj.entries) : true);
} Try / catch
try {
const { count } = await getDirectoryFileCount({ user, repo, path });
} catch (e) {
if (e.prettyMessage === 'directory not found') {
// correct the path/branch or hide the badge
} else throw e;
} Prevention
- Browse the path on github.com before wiring a badge to it.
- Remember paths are case-sensitive.
- Update badge paths after folder renames or branch deletions.
When it happens
Trigger: Requesting directory-file-count where `path` names a folder that doesn't exist on the given branch/ref (deleted, renamed, or never created), so GraphQL's object on that path is null.
Common situations: Repository restructure (src/ moved or renamed to lib/) leaving badges stale; wrong branch param where the folder only exists on another branch; case-sensitivity mismatches in the path.
Related errors
- not a directory
- 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/c19067dfe3c4e4c9.
Report an issue: GitHub.