{"record":{"id":"0d2dd15a9c7098b9","repo":"openai/codex","slug":"prettier-failed-with-status-status","errorCode":null,"errorMessage":"Prettier failed with status {status}","messagePattern":"Prettier failed with status (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"codex-rs/app-server-protocol/src/export.rs","lineNumber":182,"sourceCode":"\n            Ok(())\n        })?;\n    }\n\n    // Optionally run Prettier on all generated TS files.\n    if options.run_prettier\n        && let Some(prettier_bin) = prettier\n        && !ts_files.is_empty()\n    {\n        let status = Command::new(prettier_bin)\n            .arg(\"--write\")\n            .arg(\"--log-level\")\n            .arg(\"warn\")\n            .args(ts_files.iter().map(|p| p.as_os_str()))\n            .status()\n            .with_context(|| format!(\"Failed to invoke Prettier at {}\", prettier_bin.display()))?;\n        if !status.success() {\n            return Err(anyhow!(\"Prettier failed with status {status}\"));\n        }\n    }\n\n    trim_trailing_whitespace_in_ts_files(&ts_files)?;\n\n    Ok(())\n}\n\npub fn generate_json(out_dir: &Path) -> Result<()> {\n    generate_json_with_experimental(out_dir, /*experimental_api*/ false)\n}\n\npub fn generate_internal_json_schema(out_dir: &Path) -> Result<()> {\n    ensure_dir(out_dir)?;\n    write_json_schema::<RolloutLine>(out_dir, \"RolloutLine\")?;\n    Ok(())\n}\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/app-server-protocol/src/export.rs#L164-L200","documentation":"After writing the .ts files, generate_ts_with_options runs the caller-supplied Prettier binary with --write --log-level warn over all generated files. A non-zero exit produces this error. A missing or unlaunchable binary produces a different error (Failed to invoke Prettier at ...); this one means Prettier ran and exited non-zero, almost always because at least one generated file contains TypeScript that Prettier cannot parse.","triggerScenarios":"Running the TS export with run_prettier true when generated output is syntactically invalid (a protocol type whose TS derive emitted broken syntax), or when the pinned Prettier is too old for the emitted syntax; with log-level warn, the parse error is the visible stderr output.","commonSituations":"Adding or editing a protocol type whose generated TS breaks the parser; a stale pinned Prettier in node_modules after syntax changes; CI resolving a different Prettier version than local runs.","solutions":["Run Prettier manually over the output tree to get the failing file and parse error, for example npx prettier --write 'codex-rs/app-server-protocol/ts/**/*.ts'.","Open the file Prettier names: invalid generated TS means the exporting Rust type or its derive needs fixing, not the formatter.","Upgrade the Prettier binary passed to generate_ts_with_options if it predates the emitted syntax.","To isolate export from formatting during debugging only, pass GenerateTsOptions with run_prettier false."],"exampleFix":"// before\nlet opts = GenerateTsOptions::default(); // run_prettier: true\n\n// after (debugging: decouple export from formatting)\nlet opts = GenerateTsOptions {\n    run_prettier: false,\n    ..GenerateTsOptions::default()\n};\n// then format by hand to see which file fails to parse:\n//   npx prettier --write \"codex-rs/app-server-protocol/ts/**/*.ts\"","handlingStrategy":"validation","validationCode":"// Verify the Prettier binary before running the export:\nlet status = std::process::Command::new(&prettier_bin)\n    .arg(\"--version\")\n    .status()\n    .with_context(|| format!(\"prettier unusable at {}\", prettier_bin.display()))?;\nif !status.success() {\n    return Err(anyhow!(\"prettier --version failed; fix the toolchain first\"));\n}","typeGuard":null,"tryCatchPattern":"if let Err(err) = generate_ts_with_options(out_dir, Some(&prettier_bin), opts) {\n    if err.to_string().contains(\"Prettier failed with status\") {\n        // Generated TS likely has a syntax error: run Prettier manually on\n        // out_dir to get the file and parse error, then fix the exporting type.\n    }\n}","preventionTips":["Pin the Prettier version used by export jobs and bump it with the emitted syntax.","Run Prettier manually on generated output whenever TS-deriving protocol types change.","Keep run_prettier enabled in CI so invalid generated TS fails the build instead of shipping."],"tags":["prettier","typescript","codegen","formatting","export"],"backgroundTag":"prettier-format-failed","analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}