{"record":{"id":"cc0efd323754a9d7","repo":"badges/shields","slug":"makebadge-takes-an-argument-of-type-object","errorCode":null,"errorMessage":"makeBadge takes an argument of type object","messagePattern":"makeBadge takes an argument of type object","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"badge-maker/lib/index.js","lineNumber":11,"sourceCode":"/**\n * @module badge-maker\n */\n\nimport _makeBadge from './make-badge.js'\n\nexport class ValidationError extends Error {}\n\nfunction _validate(format) {\n  if (format !== Object(format)) {\n    throw new ValidationError('makeBadge takes an argument of type object')\n  }\n\n  if (!('message' in format)) {\n    throw new ValidationError('Field `message` is required')\n  }\n\n  const stringFields = ['labelColor', 'color', 'message', 'label', 'logoBase64']\n  stringFields.forEach(function (field) {\n    if (field in format && typeof format[field] !== 'string') {\n      throw new ValidationError(`Field \\`${field}\\` must be of type string`)\n    }\n  })\n\n  if ('links' in format) {\n    if (!Array.isArray(format.links)) {\n      throw new ValidationError('Field `links` must be an array of strings')\n    } else {\n      if (format.links.length > 2) {","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/badge-maker/lib/index.js#L1-L29","documentation":"makeBadge() requires a single object argument describing the badge. In _validate (badge-maker/lib/index.js:10) the library checks `format !== Object(format)`; primitives like strings, numbers, booleans, null, or undefined fail this check because Object(primitive) wraps them in a new object. This ensures callers pass a well-formed badge descriptor before any rendering happens.","triggerScenarios":"Calling makeBadge('flat'), makeBadge(null), makeBadge(undefined), makeBadge(42), or makeBadge(true). Any non-object value (including null, which Object(null) !== null) passed to makeBadge throws this immediately.","commonSituations":"Passing a legacy positional-argument signature from the old badges/gh-badges API (makeBadge('label', 'message', 'color', 'flat')), accidentally forwarding a variable that is undefined due to a config-loading failure, or TypeScript/JS callers building the options object conditionally and forgetting it entirely.","solutions":["Pass a single options object: makeBadge({ label: 'build', message: 'passing' })","If migrating from gh-badges/badge-maker v3 positional API, convert the four positional arguments into an object","Guard the input before calling: only call makeBadge when the descriptor exists and is an object"],"exampleFix":"// before\nconst svg = makeBadge('build', 'passing', '#4c1', 'flat')\n// after\nconst svg = makeBadge({ label: 'build', message: 'passing', color: '#4c1', style: 'flat' })","handlingStrategy":"type-guard","validationCode":"if (badge == null || typeof badge !== 'object' || Array.isArray(badge)) {\n  throw new Error('badge descriptor must be a non-null object')\n}\nconst svg = makeBadge(badge)","typeGuard":"function isBadgeDescriptor(v) {\n  return typeof v === 'object' && v !== null && !Array.isArray(v)\n}","tryCatchPattern":"import { makeBadge, ValidationError } from 'badge-maker'\ntry {\n  return makeBadge(input)\n} catch (e) {\n  if (e instanceof ValidationError && e.message.includes('argument of type object')) {\n    return makeBadge({ message: String(input) })\n  }\n  throw e\n}","preventionTips":["Always construct the descriptor object explicitly; never forward bare primitives","When migrating from gh-badges positional API, wrap args in a single object","Enable TypeScript and type the parameter as BadgeDescriptor"],"tags":["validation","argument-type","api-usage"],"backgroundTag":"invalid-argument-type","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}