fix: reorder argument validation flow (fixes #18) - #19
Open
yunaremaia wants to merge 1 commit into
Open
Conversation
Reorder validation checks in src/main.cpp to avoid misleading errors: 1. hydra::exists(csv_path) -> Error: file does not exist 2. hydra::is_directory(csv_path) -> Error: path is a directory 3. hydra::has_csv_extension(csv_path) -> Error: file must be a .csv file 4. hydra::is_readable_file(csv_path) -> Could not open file Previously the extension was checked before existence, which produced 'file must be a .csv file' even for non-existent paths.
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.
Summary
Reorders the argument validation flow in
src/main.cppto produce accurate, non-misleading error messages.Previously the extension check ran before the existence check, so a non-existent file such as
non_existent.csvcould be rejected withfile must be a .csv file. This PR fixes the order as requested in #18.Changes
Reordered validation in
src/main.cppto:hydra::exists(csv_path)→Error: file does not exist: <path>hydra::is_directory(csv_path)→Error: path is a directory: <path>hydra::has_csv_extension(csv_path)→Error: file must be a .csv filehydra::is_readable_file(csv_path)→Could not open file: <path>No other files changed. Messages and helpers remain unchanged, only the guard order.
Validation
Built locally with CMake + Make (FTXUI 7.0.3, GCC 16.2.1) and tested manually:
hydra non_existent.csvError: file does not exist: non_existent.csvhydra my_folder.csv(directory)Error: path is a directory: my_folder.csvhydra data.txt(existing non-csv)Error: file must be a .csv filehydra valid.csv(valid file)hydra non_existent.txtfile does not exist(not misleading csv error)Existing test suite (
hydra_tests) still passes.Fixes #18