badges/shields · error · InvalidParameter

extension is applicable for type file only

Error message

extension is applicable for type file only

What it means

In the same transform(), passing an `extension` param while `type` is set to something other than 'file' throws InvalidParameter 'extension is applicable for type file only'. Extension filtering only makes sense for blob (file) entries; trees (directories) have no extension. The service validates this combination up front.

Source

Thrown at services/github/github-directory-file-count.service.js:129

                }
              }
            }
          }
        }
      `,
      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 {
      count: files.length,
    }
  }

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Remove the `extension` query param if you want to count directories.
  2. Set `type=file` when using `extension` so files of that extension are counted.
  3. Use `type=file&extension=js` explicitly if your intent is counting .js files.

Example fix

// before
/service/github/directory-file-count/user/repo.json?type=dir&extension=js
// after
/service/github/directory-file-count/user/repo.json?type=file&extension=js
Defensive patterns

Strategy: validation

Validate before calling

// validate param combination before calling
if (extension != null && type !== 'file') {
  throw new Error('extension is applicable for type file only');
}

Type guard

function isValidCountQuery(query) {
  return query.extension == null || query.type === 'file';
}

Try / catch

try {
  const { count } = await getDirectoryFileCount({ user, repo, type, extension });
} catch (e) {
  if (e.prettyMessage === 'extension is applicable for type file only') {
    // drop extension or set type=file and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Calling directory-file-count with query params like ?type=dir&extension=js (or extension with no type where the resolved default isn't file), triggering the guard `type !== 'file' && extension`.

Common situations: Copy-pasting badge URLs and editing type but leaving extension in place; misunderstanding that extension counts only files, not subdirectories.

Related errors


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