fix: improve input validation in check_log_type#42
Open
ujjwx1 wants to merge 2 commits intohpc-io:masterfrom
Open
fix: improve input validation in check_log_type#42ujjwx1 wants to merge 2 commits intohpc-io:masterfrom
ujjwx1 wants to merge 2 commits intohpc-io:masterfrom
Conversation
Previously, any path not ending in .darshan was assumed to be a Recorder directory, causing a misleading 'Unable to open recorder folder' error for unsupported file types like .txt or .csv. Now explicitly checks if the path is a directory before treating it as a Recorder folder. If neither, displays a clear error: 'Unsupported file format. Please provide a .darshan file or a Recorder directory.'
There was a problem hiding this comment.
Pull request overview
Improves CLI input validation in check_log_type() so only directories are treated as Recorder logs and unsupported inputs produce a clearer error, reducing misleading “Unable to open recorder folder” messages.
Changes:
- Treats inputs as Recorder logs only when
os.path.isdir(path)is true. - Adds a clearer error message for unsupported inputs (neither a
.darshanfile nor a directory).
Comments suppressed due to low confidence (3)
drishti/reporter.py:43
- The new
elsebranch triggers for any non-.darshanpath that isn’t a directory, including a non-existent path. That will now report “Unsupported file format…”, which is misleading when the user simply provided a missing file/folder. Consider checkingos.path.exists(path)first and emitting the existing “Unable to open …”/os.EX_NOINPUTpath-not-found error, and only using the unsupported-format message when the path exists but is neither a.darshanfile nor a directory.
elif os.path.isdir(path):
return LOG_TYPE_RECORDER
else:
print('Unsupported file format. Please provide a .darshan file or a Recorder directory.')
sys.exit(1)
drishti/reporter.py:43
- For consistency with the other error exits in this project (e.g.,
os.EX_NOINPUT/os.EX_DATAERR), consider avoiding a rawsys.exit(1)here and using an appropriateos.EX_*code (oftenos.EX_USAGEfor invalid arguments oros.EX_DATAERRfor invalid input data).
print('Unsupported file format. Please provide a .darshan file or a Recorder directory.')
sys.exit(1)
drishti/reporter.py:38
- There’s trailing whitespace after
else:on this line. Trimming it (and optionally dropping theelseafter an unconditionalsys.exit) helps keep diffs clean and avoids whitespace-only lint failures if tooling is added later.
else:
return LOG_TYPE_DARSHAN
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Previously, both missing paths and unsupported file formats showed the same misleading error. Now distinguishes between: - Path does not exist: clear not-found error - Path exists but wrong format: unsupported format error Also removed trailing whitespace after else clause.
Author
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 #41
Previously, any path not ending in .darshan was assumed to be a Recorder directory, causing a misleading 'Unable to open recorder folder' error for unsupported file types like .txt or .csv.
Now explicitly checks if the path is a directory before treating it as a Recorder folder. If neither, displays a clear error: 'Unsupported file format. Please provide a .darshan file or a Recorder directory.'