Replace panic with user-friendly error for empty test contents - #172
Merged
Conversation
When a zero-length file is provided (or a language file with no words), ttyper previously panicked with 'Empty test contents.' Now it prints a helpful error message to stderr and exits cleanly. Also guards against the same issue when restarting with 'r' from the results screen, which could panic if gen_contents returned an empty vec (the restart now just stays on the results screen instead). Fixes #78
Collaborator
|
Could you please add a test before I close this? Logic is good. @ctonneslan |
- gen_contents_empty_file_returns_empty_vec: verifies empty file produces empty vec (which triggers the clean error message) - gen_contents_nonempty_file_returns_words: verifies normal file produces non-empty contents Added tempfile as a dev dependency for test temp dirs.
Author
|
Added two tests:
All 7 tests pass. Added |
Collaborator
|
Thank you ! @ctonneslan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #78
When you pass ttyper an empty file (or a language file with no words), it panics with
Empty test contents.which isn't great for users. This replaces that with a clean error message on stderr explaining what went wrong.Also handles the case where you restart with
rfrom the results screen andgen_contents()returns an empty vec. Previously this could trigger an index-out-of-bounds panic in the render code. Now it just stays on the results screen.Changes
src/main.rs: Replacepanic!witheprintln!+process::exit(1)for empty contents on startupsrc/main.rs: Guard restart path against empty contentsTesting
Tested with
echo -n "" > /tmp/empty.txt && cargo run -- /tmp/empty.txt(prints error, exits cleanly instead of panicking).