{"record":{"id":"89ff7ec224ebf54d","repo":"affaan-m/ECC","slug":"result-stderr-tostring-formatter-exited-with-status-result","errorCode":null,"errorMessage":"result.stderr?.toString() || `Formatter exited with status ${result.status}`","messagePattern":"result\\.stderr\\?\\.toString\\(\\) \\|\\| `Formatter exited with status (.+?)`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/hooks/post-edit-format.js","lineNumber":70,"sourceCode":"        // Biome: `check --write` = format + lint in one pass\n        // Prettier: `--write` = format only\n        const args = formatter === 'biome' ? [...resolved.prefix, 'check', '--write', resolvedFilePath] : [...resolved.prefix, '--write', resolvedFilePath];\n\n        if (process.platform === 'win32' && resolved.bin.endsWith('.cmd')) {\n          // Windows: .cmd files require shell to execute. Guard against\n          // command injection by rejecting paths with shell metacharacters.\n          if (UNSAFE_PATH_CHARS.test(resolvedFilePath)) {\n            throw new Error('File path contains unsafe shell characters');\n          }\n          const result = spawnSync(resolved.bin, args, {\n            cwd: projectRoot,\n            shell: true,\n            stdio: 'pipe',\n            timeout: 15000\n          });\n          if (result.error) throw result.error;\n          if (typeof result.status === 'number' && result.status !== 0) {\n            throw new Error(result.stderr?.toString() || `Formatter exited with status ${result.status}`);\n          }\n        } else {\n          execFileSync(resolved.bin, args, {\n            cwd: projectRoot,\n            stdio: ['pipe', 'pipe', 'pipe'],\n            timeout: 15000\n          });\n        }\n      } catch {\n        // Formatter not installed, file missing, or failed — non-blocking\n      }\n    }\n  } catch {\n    // Invalid input — pass through\n  }\n\n  return rawInput;\n}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/hooks/post-edit-format.js#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"Saving a file with syntax errors the formatter cannot parse, misconfigured formatter for the file type, formatter version whose config schema no longer matches.","solutions":["Read the stderr text in the error message — it contains the formatter's own diagnostics","Fix the lint/syntax issues reported for the file","Validate the formatter config (biome.json) against the installed formatter version","If stderr was empty, run the formatter manually to see real output"],"exampleFix":"// before (opaque error: 'Formatter exited with status 1')\n// after\nnpx biome check --write src/foo.ts   // run manually to see actual diagnostics","handlingStrategy":"try-catch","validationCode":"// pre-check formatter availability\nconst probe = spawnSync(resolved.bin, ['--version'], { shell: true, timeout: 5000 });\nif (probe.error || probe.status !== 0) throw new Error('Formatter not runnable');","typeGuard":null,"tryCatchPattern":"try {\n  run({ filePath });\n} catch (err) {\n  if (/Formatter exited with status/.test(err.message) || err.stderr) {\n    console.error('Formatter failed:', err.message);\n    return; // do not block the edit; log for follow-up\n  }\n  throw err;\n}","preventionTips":["Keep formatter config files valid for the installed formatter version","Run formatters locally before committing so failures are not surprising","Pin formatter versions so config schema and binary stay in sync"],"tags":["formatter","windows","exit-code","hooks"],"backgroundTag":"command-exited-nonzero","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}