affaan-m/ECC · error

Binary name must be a non-empty string

Error message

Binary name must be a non-empty string

What it means

getExecCommand() builds a command line to execute a binary through the detected package manager (e.g. 'npx prettier --check .'). The first guard rejects a binary parameter that is missing, not a string, or an empty string. The library requires a concrete binary name because it interpolates the value into a shell command and an empty name would produce a broken or dangerous command.

Solutions

  1. Pass a concrete non-empty binary name string, e.g. getExecCommand('prettier', '--check .').
  2. Log or inspect the value being passed right before the call to find where it becomes empty/undefined.
  3. Fix the upstream source: default config value, correct env var (e.g. BINARY), or correct object property name.
  4. Guard the call site: skip or throw a clearer domain error when the binary is unknown instead of forwarding an empty value.

Example fix

// before
const binary = config.tools.formatter?.name; // undefined when key missing
run(getExecCommand(binary, args))
// after
const binary = config.tools.formatter?.name;
if (!binary) throw new Error('No formatter binary configured');
run(getExecCommand(binary, args))
Defensive patterns

Strategy: validation

Validate before calling

if (typeof binary !== 'string' || binary.length === 0) {
  throw new Error(`Binary must be a non-empty string, got: ${JSON.stringify(binary)}`);
}
getExecCommand(binary, args);

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.length > 0;
}

Try / catch

try {
  const cmd = getExecCommand(binary, args);
} catch (e) {
  if (e.message === 'Binary name must be a non-empty string') {
    console.error(`Binary lookup failed for config key; resolved to ${JSON.stringify(binary)}`);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling getExecCommand(''), getExecCommand(undefined), getExecCommand(null), getExecCommand(42), or any falsy/non-string first argument. Typically happens when the binary name is computed from config, an env var, or a lookup that returned nothing.

Common situations: Config file where the tool/binary field is blank or missing; a variable that is undefined because of a typo or failed lookup; refactors that changed the call signature and dropped the binary argument; passing options object as the first argument by mistake.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/e39761b2c59eebb1. Report an issue: GitHub.

Appendix: source

Thrown at scripts/lib/package-manager.js:332

      return pm.config.devCmd;
    default:
      return `${pm.config.runCmd} ${script}`;
  }
}

// Allowed characters in arguments: alphanumeric, whitespace, dashes, dots, slashes,
// equals, colons, commas, quotes, @. Rejects shell metacharacters like ; | & ` $ ( ) { } < > !
const SAFE_ARGS_REGEX = /^[@a-zA-Z0-9\s_./:=,'"*+-]+$/;

/**
 * Get the command to execute a package binary
 * @param {string} binary - Binary name (e.g., "prettier", "eslint")
 * @param {string} args - Arguments to pass
 * @throws {Error} If binary name or args contain unsafe characters
 */
function getExecCommand(binary, args = '', options = {}) {
  if (!binary || typeof binary !== 'string') {
    throw new Error('Binary name must be a non-empty string');
  }
  if (!SAFE_NAME_REGEX.test(binary)) {
    throw new Error(`Binary name contains unsafe characters: ${binary}`);
  }
  if (args && typeof args === 'string' && !SAFE_ARGS_REGEX.test(args)) {
    throw new Error(`Arguments contain unsafe characters: ${args}`);
  }

  const pm = getPackageManager(options);
  return `${pm.config.execCmd} ${binary}${args ? ' ' + args : ''}`;
}

/**
 * Interactive prompt for package manager selection
 * Returns a message for Claude to show to user
 *
 * NOTE: Does NOT spawn child processes to check availability.
 * Lists all supported PMs and shows how to configure preference.

View on GitHub (pinned to 8321021c54)