Skip to content

fix: improve input validation in check_log_type#42

Open
ujjwx1 wants to merge 2 commits intohpc-io:masterfrom
ujjwx1:fix/input-validation
Open

fix: improve input validation in check_log_type#42
ujjwx1 wants to merge 2 commits intohpc-io:masterfrom
ujjwx1:fix/input-validation

Conversation

@ujjwx1
Copy link
Copy Markdown

@ujjwx1 ujjwx1 commented Mar 4, 2026

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.'

image

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.'
Copilot AI review requested due to automatic review settings March 4, 2026 18:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .darshan file nor a directory).
Comments suppressed due to low confidence (3)

drishti/reporter.py:43

  • The new else branch triggers for any non-.darshan path 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 checking os.path.exists(path) first and emitting the existing “Unable to open …”/os.EX_NOINPUT path-not-found error, and only using the unsupported-format message when the path exists but is neither a .darshan file 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 raw sys.exit(1) here and using an appropriate os.EX_* code (often os.EX_USAGE for invalid arguments or os.EX_DATAERR for 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 the else after an unconditional sys.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.
@ujjwx1
Copy link
Copy Markdown
Author

ujjwx1 commented Mar 9, 2026

Hi @jeanbez @sbyna , just following up on this PR. It improves input validation in check_log_type. Please let me know if any changes are needed or if I can clarify anything for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Misleading error message for unsupported file formats

2 participants