{"record":{"id":"b8a9f21c6069d6b8","repo":"badges/shields","slug":"extension-is-applicable-for-type-file-only","errorCode":null,"errorMessage":"extension is applicable for type file only","messagePattern":"extension is applicable for type file only","errorType":"validation","errorClass":"InvalidParameter","httpStatus":400,"severity":"error","filePath":"services/github/github-directory-file-count.service.js","lineNumber":129,"sourceCode":"                }\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 {\n      count: files.length,\n    }\n  }\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/github/github-directory-file-count.service.js#L111-L147","documentation":"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.","triggerScenarios":"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`.","commonSituations":"Copy-pasting badge URLs and editing type but leaving extension in place; misunderstanding that extension counts only files, not subdirectories.","solutions":["Remove the `extension` query param if you want to count directories.","Set `type=file` when using `extension` so files of that extension are counted.","Use `type=file&extension=js` explicitly if your intent is counting .js files."],"exampleFix":"// before\n/service/github/directory-file-count/user/repo.json?type=dir&extension=js\n// after\n/service/github/directory-file-count/user/repo.json?type=file&extension=js","handlingStrategy":"validation","validationCode":"// validate param combination before calling\nif (extension != null && type !== 'file') {\n  throw new Error('extension is applicable for type file only');\n}","typeGuard":"function isValidCountQuery(query) {\n  return query.extension == null || query.type === 'file';\n}","tryCatchPattern":"try {\n  const { count } = await getDirectoryFileCount({ user, repo, type, extension });\n} catch (e) {\n  if (e.prettyMessage === 'extension is applicable for type file only') {\n    // drop extension or set type=file and retry\n  } else throw e;\n}","preventionTips":["Always pair extension with type=file in badge URLs.","Strip stale query params when copying badge URL templates.","Validate query params in CI when generating badges."],"tags":["github","invalid-parameter","query-params","validation"],"backgroundTag":"invalid-parameter-combination","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}