Skip to content

Crash on startup when no argument is given or the file doesn't exist #1

Closed

Description

@frapank

I want to report three problems that happen during startup:

  1. If you run rusk (or cargo run) without arguments, the program panics at src/main.rs:69 (expect("Use: rusk ")).
  2. If you run rusk missing.txt with a file that doesn't exist, the program panics at src/editor/buffer.rs:15 (read_to_string(file).unwrap()).
  3. In both cases the error message is printed in a "staircase" pattern, and after the crash the terminal no longer responds correctly to input.

The causes are:

  1. The program enables raw mode (enable_raw_mode()) and the alternate screen before reading the arguments. In raw mode \n doesn't move the cursor back to the start of the line, which is why the output looks like a staircase. Since the program exits with a panic, disable_raw_mode() is never called and the terminal stays in raw mode.
  2. buffer::fetch assumes the file always exists and calls unwrap() on the result of read_to_string.

To fix it, we can read the argument before enabling raw mode. If it's missing, print the usage to stderr and exit with code 1 instead of panicking.
For the missing file, we can just create it and handle it with an empty buffer.
Finally, we can add a panic hook that disables raw mode.

Activity

  1. self-assigned this
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions