You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash on startup when no argument is given or the file doesn't exist #1
I want to report three problems that happen during startup:
If you run rusk (or cargo run) without arguments, the program panics at src/main.rs:69 (expect("Use: rusk ")).
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()).
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:
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.
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