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.

Solutions

  1. Verify the folder exists at that exact path on the requested branch (browse it on github.com).
  2. Update the badge path after repository restructures/renames.
  3. 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

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


AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30). Data as JSON: /api/errors/c19067dfe3c4e4c9. Report an issue: GitHub.

Appendix: 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)