affaan-m/ECC · error · Error

--cwd must not contain a NUL byte.

Error message

--cwd must not contain a NUL byte.

What it means

validateCwd rejects any --cwd value containing a NUL byte (\0). NUL bytes are not valid in filesystem paths and can truncate strings in C-level path APIs, so the script fails fast rather than passing a corrupt path to the OS. This is a defensive validation before spawning the terminal process.

Solutions

  1. Inspect the cwd value and remove the NUL byte (re-trim/escape the source string).
  2. If generated programmatically, sanitize with `value.replace(/\0/g, '')` or validate before passing.
  3. Fix the upstream producer (config file, command substitution) that introduced the NUL byte.

Example fix

// before
spawnScript(['--cwd', someBuffer.toString()]); // contains \0
// after
const cwd = someBuffer.toString('utf8').replace(/\0/g, '');
spawnScript(['--cwd', cwd]);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof cwd !== 'string' || cwd.includes('\0')) throw new Error('cwd must be a NUL-free string');

Type guard

function isCleanPathValue(v) {
  return typeof v === 'string' && v.length > 0 && !v.includes('\0');
}

Try / catch

try {
  parseArgs(process.argv);
} catch (e) {
  if (/must not contain a NUL byte/.test(e.message)) {
    console.error('cwd contains a NUL byte; sanitize the value source');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling open-terminal.js with `--cwd $'some\0path'`, typically from programmatic argv construction, shell interpolation of binary data, or a config file that embedded a raw NUL.

Common situations: Scripts that build argv from concatenated buffers or env vars containing binary data; JSON configs where \u0000 slipped in; buggy templating that inserted control characters.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at skills/terminal-opener/scripts/open-terminal.js:47

  --help, -h         Show this help.

Always pass the executable and arguments as separate entries after --.
Shell command strings are not accepted.
`;
}

function isAbsolutePath(value) {
  return path.isAbsolute(value) || path.win32.isAbsolute(value);
}

function validateTerminalName(value) {
  if (!/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(value)) {
    throw new Error('Invalid terminal name; use a simple adapter name such as wezterm.');
  }
}

function validateCwd(value) {
  if (value.includes('\0')) throw new Error('--cwd must not contain a NUL byte.');
  if (!isAbsolutePath(value)) throw new Error('--cwd must be an absolute path.');
}

function validateExecutable(value) {
  if (!value || /[\0\r\n]/.test(value)) {
    throw new Error('Executable must be a non-empty argv entry without control bytes.');
  }

  const whitespaceIndex = value.search(/\s/);
  const separatorIndexes = [value.indexOf('/'), value.indexOf('\\')].filter(index => index >= 0);
  const firstSeparatorIndex = separatorIndexes.length > 0 ? Math.min(...separatorIndexes) : -1;
  const resemblesExecutablePath = isAbsolutePath(value)
    || (firstSeparatorIndex >= 0 && (whitespaceIndex < 0 || firstSeparatorIndex < whitespaceIndex));

  if (whitespaceIndex >= 0 && !resemblesExecutablePath) {
    throw new Error(
      'Executable must be one argv entry, not an interpolated shell command string.'
    );

View on GitHub (pinned to 8321021c54)