openai/codex · error · anyhow::Error
Prettier failed with status {status}
Error message
Prettier failed with status {status} What it means
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.
Source
Thrown at codex-rs/app-server-protocol/src/export.rs:182
Ok(())
})?;
}
// Optionally run Prettier on all generated TS files.
if options.run_prettier
&& let Some(prettier_bin) = prettier
&& !ts_files.is_empty()
{
let status = Command::new(prettier_bin)
.arg("--write")
.arg("--log-level")
.arg("warn")
.args(ts_files.iter().map(|p| p.as_os_str()))
.status()
.with_context(|| format!("Failed to invoke Prettier at {}", prettier_bin.display()))?;
if !status.success() {
return Err(anyhow!("Prettier failed with status {status}"));
}
}
trim_trailing_whitespace_in_ts_files(&ts_files)?;
Ok(())
}
pub fn generate_json(out_dir: &Path) -> Result<()> {
generate_json_with_experimental(out_dir, /*experimental_api*/ false)
}
pub fn generate_internal_json_schema(out_dir: &Path) -> Result<()> {
ensure_dir(out_dir)?;
write_json_schema::<RolloutLine>(out_dir, "RolloutLine")?;
Ok(())
}
View on GitHub (pinned to 339751715c)
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.
Example fix
// before
let opts = GenerateTsOptions::default(); // run_prettier: true
// after (debugging: decouple export from formatting)
let opts = GenerateTsOptions {
run_prettier: false,
..GenerateTsOptions::default()
};
// then format by hand to see which file fails to parse:
// npx prettier --write "codex-rs/app-server-protocol/ts/**/*.ts" Defensive patterns
Strategy: validation
Validate before calling
// Verify the Prettier binary before running the export:
let status = std::process::Command::new(&prettier_bin)
.arg("--version")
.status()
.with_context(|| format!("prettier unusable at {}", prettier_bin.display()))?;
if !status.success() {
return Err(anyhow!("prettier --version failed; fix the toolchain first"));
} Try / catch
if let Err(err) = generate_ts_with_options(out_dir, Some(&prettier_bin), opts) {
if err.to_string().contains("Prettier failed with status") {
// Generated TS likely has a syntax error: run Prettier manually on
// out_dir to get the file and parse error, then fix the exporting type.
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- TypeScript header worker panicked
- expected bundle root to be an object
- expected bundle definitions map
- expected v2 namespace in bundle definitions
AI-assisted analysis of openai/codex@339751715c (2026-08-25).
Data as JSON: /api/errors/0d2dd15a9c7098b9.
Report an issue: GitHub.