Skip to content

cli: convert -o can leave a truncated file and panics on IO errors #855

Open

Description

@bpowers

simlin convert -o <path> truncates the destination file and then writes to it, unwrapping every IO result.
A failure part-way through (disk full) leaves a truncated file where the user's previous good file was, and the CLI panics with a backtrace instead of printing an error.
It should write through simlin_engine::io::atomic_write (temp file, fsync, rename) and report IO errors with die!.

render -o and equations --output use the same pattern and should get the same fix.

Example

// src/simlin-cli/src/main.rs, Command::Convert
let output_path = output.unwrap_or_else(|| PathBuf::from("/dev/stdout"));
let mut output_file = File::create(&output_path).unwrap();
output_file.write_all(&buf).unwrap();

Why it matters

Low: only IO failures mid-write are exposed (conversion errors are caught before the file is opened), and the CLI is mainly a testing tool.
But the failure destroys the file being overwritten.
simlin-serve already saves through atomic_write for this reason.

Fix

Write to stdout through io::stdout() when no output path is given, rather than opening /dev/stdout as a file (a rename cannot target it).
For a named path, call atomic_write and die! with the path and the OS error on failure.
One helper used by convert, render and equations covers all three.

Pointers

  • src/simlin-cli/src/main.rs: Command::Convert and Command::Render arms, print_equations
  • src/simlin-engine/src/io.rs: atomic_write
  • src/simlin-serve/src/writer.rs: atomic_write_to, an existing caller

Activity

  1. added
    engine
    bug
    on Oct 12, 2026
  2. changed the title [-]cli: convert -o output write is non-atomic and panics on IO errors[/-] [+]cli: convert -o can leave a truncated file and panics on IO errors[/+] on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions