Skip to content

nldi: raise ValueError (not TypeError) for invalid navigation mode#258

Merged
thodson-usgs merged 2 commits into
DOI-USGS:mainfrom
thodson-usgs:fix/nldi-navigation-mode-valueerror
May 4, 2026
Merged

nldi: raise ValueError (not TypeError) for invalid navigation mode#258
thodson-usgs merged 2 commits into
DOI-USGS:mainfrom
thodson-usgs:fix/nldi-navigation-mode-valueerror

Conversation

@thodson-usgs
Copy link
Copy Markdown
Collaborator

@thodson-usgs thodson-usgs commented May 4, 2026

Summary

_validate_navigation_mode raises TypeError for an invalid string value (e.g., "XX"). The sister helper _validate_data_source in the same file already raises ValueError for the same kind of bad-input case. TypeError is reserved for cases where an arguments type is wrong; an unrecognized navigation-mode string is a value error, so callers writing except ValueError: would not catch it today.

# dataretrieval/nldi.py:486-489
def _validate_navigation_mode(navigation_mode: str):
    navigation_mode = navigation_mode.upper()
    if navigation_mode not in ("UM", "DM", "UT", "DD"):
        raise ValueError(f"Invalid navigation mode '{navigation_mode}'")  # was TypeError

One-line change; no regression test (the assertion would just re-state the diff).

Related PRs

This is a strict subset of #252 (nldi-cleanup), which also changes TypeError -> ValueError here as part of a larger refactor (extracts _VALID_NAVIGATION_MODES, normalizes input and returns it, adds a None guard). If #252 lands first, this PR can be closed.

#246 (nldi-data-source-validation) also touches nldi.py but a different function (_validate_data_source); no conflict.

🤖 Generated with Claude Code

thodson-usgs and others added 2 commits May 4, 2026 01:51
`_validate_navigation_mode` raised `TypeError` for an invalid string
value (e.g. "ABC"). The sister helper `_validate_data_source` in the
same file already raises `ValueError` for the same kind of bad-input
case. `TypeError` is reserved for cases where an argument's type is
wrong; an unrecognized navigation-mode string is a value error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

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

Aligns NLDI input validation semantics with Python conventions by raising ValueError (not TypeError) when a caller provides an unrecognized navigation-mode value, matching existing validation behavior in the same module.

Changes:

  • Change _validate_navigation_mode to raise ValueError for invalid navigation mode strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thodson-usgs thodson-usgs marked this pull request as ready for review May 4, 2026 14:53
@thodson-usgs thodson-usgs merged commit 4570192 into DOI-USGS:main May 4, 2026
12 checks passed
@thodson-usgs thodson-usgs deleted the fix/nldi-navigation-mode-valueerror branch May 4, 2026 14:54
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.

2 participants