badges/shields · error · ValidationError

makeBadge takes an argument of type object

Error message

makeBadge takes an argument of type object

What it means

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.

Source

Thrown at badge-maker/lib/index.js:11

/**
 * @module badge-maker
 */

import _makeBadge from './make-badge.js'

export class ValidationError extends Error {}

function _validate(format) {
  if (format !== Object(format)) {
    throw new ValidationError('makeBadge takes an argument of type object')
  }

  if (!('message' in format)) {
    throw new ValidationError('Field `message` is required')
  }

  const stringFields = ['labelColor', 'color', 'message', 'label', 'logoBase64']
  stringFields.forEach(function (field) {
    if (field in format && typeof format[field] !== 'string') {
      throw new ValidationError(`Field \`${field}\` must be of type string`)
    }
  })

  if ('links' in format) {
    if (!Array.isArray(format.links)) {
      throw new ValidationError('Field `links` must be an array of strings')
    } else {
      if (format.links.length > 2) {

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Pass a single options object: makeBadge({ label: 'build', message: 'passing' })
  2. If migrating from gh-badges/badge-maker v3 positional API, convert the four positional arguments into an object
  3. Guard the input before calling: only call makeBadge when the descriptor exists and is an object

Example fix

// before
const svg = makeBadge('build', 'passing', '#4c1', 'flat')
// after
const svg = makeBadge({ label: 'build', message: 'passing', color: '#4c1', style: 'flat' })
Defensive patterns

Strategy: type-guard

Validate before calling

if (badge == null || typeof badge !== 'object' || Array.isArray(badge)) {
  throw new Error('badge descriptor must be a non-null object')
}
const svg = makeBadge(badge)

Type guard

function isBadgeDescriptor(v) {
  return typeof v === 'object' && v !== null && !Array.isArray(v)
}

Try / catch

import { makeBadge, ValidationError } from 'badge-maker'
try {
  return makeBadge(input)
} catch (e) {
  if (e instanceof ValidationError && e.message.includes('argument of type object')) {
    return makeBadge({ message: String(input) })
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


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