affaan-m/ECC · error · Error

result.stderr?.toString() || `Formatter exited with status

Error message

result.stderr?.toString() || `Formatter exited with status ${result.status}`

What it means

When the Windows .cmd formatter exits with a non-zero status, post-edit-format.js throws an Error whose message is the formatter's stderr output, or the generic `Formatter exited with status N` when stderr is empty or unreadable. It surfaces formatter failures instead of swallowing them.

Solutions

  1. Read the stderr text in the error message — it contains the formatter's own diagnostics
  2. Fix the lint/syntax issues reported for the file
  3. Validate the formatter config (biome.json) against the installed formatter version
  4. If stderr was empty, run the formatter manually to see real output

Example fix

// before (opaque error: 'Formatter exited with status 1')
// after
npx biome check --write src/foo.ts   // run manually to see actual diagnostics
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check formatter availability
const probe = spawnSync(resolved.bin, ['--version'], { shell: true, timeout: 5000 });
if (probe.error || probe.status !== 0) throw new Error('Formatter not runnable');

Try / catch

try {
  run({ filePath });
} catch (err) {
  if (/Formatter exited with status/.test(err.message) || err.stderr) {
    console.error('Formatter failed:', err.message);
    return; // do not block the edit; log for follow-up
  }
  throw err;
}

Prevention

When it happens

Trigger: Running `biome check --write` on a file with unfixable lint/syntax errors, a broken formatter config, or a formatter crash that prints nothing to stderr.

Common situations: Saving a file with syntax errors the formatter cannot parse, misconfigured formatter for the file type, formatter version whose config schema no longer matches.

Related errors


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

Appendix: source

Thrown at scripts/hooks/post-edit-format.js:70

        // Biome: `check --write` = format + lint in one pass
        // Prettier: `--write` = format only
        const args = formatter === 'biome' ? [...resolved.prefix, 'check', '--write', resolvedFilePath] : [...resolved.prefix, '--write', resolvedFilePath];

        if (process.platform === 'win32' && resolved.bin.endsWith('.cmd')) {
          // Windows: .cmd files require shell to execute. Guard against
          // command injection by rejecting paths with shell metacharacters.
          if (UNSAFE_PATH_CHARS.test(resolvedFilePath)) {
            throw new Error('File path contains unsafe shell characters');
          }
          const result = spawnSync(resolved.bin, args, {
            cwd: projectRoot,
            shell: true,
            stdio: 'pipe',
            timeout: 15000
          });
          if (result.error) throw result.error;
          if (typeof result.status === 'number' && result.status !== 0) {
            throw new Error(result.stderr?.toString() || `Formatter exited with status ${result.status}`);
          }
        } else {
          execFileSync(resolved.bin, args, {
            cwd: projectRoot,
            stdio: ['pipe', 'pipe', 'pipe'],
            timeout: 15000
          });
        }
      } catch {
        // Formatter not installed, file missing, or failed — non-blocking
      }
    }
  } catch {
    // Invalid input — pass through
  }

  return rawInput;
}

View on GitHub (pinned to 8321021c54)