Wrap raw TypeError/RuntimeError in GMDCommandError#5
Open
karstenm1987 wants to merge 1 commit intomainfrom
Open
Wrap raw TypeError/RuntimeError in GMDCommandError#5karstenm1987 wants to merge 1 commit intomainfrom
karstenm1987 wants to merge 1 commit intomainfrom
Conversation
Two places leaked internal exceptions to users:
1. `_tokens()` used `for item in value:` with no type guard. Passing a
scalar like `gmd(country=840)` produced
TypeError: 'int' object is not iterable
instead of a clean command error. Now `_tokens()` rejects non-str /
non-list / non-tuple inputs with a `GMDCommandError(code=198)` and
a message that names the actual type received.
2. `get_available_versions()` re-raised the internal `RuntimeError`
from `_fetch_from` when both the S3 primary and GitHub fallback
failed and there was no local cache. Wrap that terminal raise in
`GMDCommandError` with a human-readable message pointing at the
likely cause (no internet / transient outage).
Internal issue: KMueller-Lab/Global-Macro-Database-Internal#414
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Tracked upstream at Global-Macro-Database-Internal#414. Same filter as the recent Stata and R PRs: fix actual bugs, skip nice-to-haves.
Bugs
Both failure paths leaked internal exception types to users instead of the package's own
GMDCommandError.1.
gmd(country=840)leakedTypeError: 'int' object is not iterableRoot cause:
_tokens()didfor item in value:with no type guard. Any scalar non-string (int, float, etc.) tripped Python's iteration protocol, not the package's own error surface. Same class of leak forvariables=840,variables=1.5, etc.2.
get_available_versions()leakedRuntimeErrorwhen both mirrors were unreachablegmd.py:333-344caught the internalRuntimeErrorfrom_fetch_from, checked the on-disk cache and a local.dtafallback, and then bare-raise'd the internal error back to the user.Fix
Two small changes:
_tokens()now rejects non-str / non-list / non-tuple inputs withGMDCommandError(code=198)and a message naming the actual type.raiseinget_available_versions()becomes araise GMDCommandError(...) from excwith a message that tells the user what probably went wrong (no internet / transient outage).Verified (live)
Out of scope
Other items in #414 are UX/consistency rather than correctness bugs and kept for separate PRs:
raw/fast/isotruthy-string coercion (raw="no"still loads raw data) — same class as the Statafast()UX wart, classified as "nice-to-have" in the Stata review.start_year/end_year— not implementing per maintainer preference.Also note: the listed-but-404 versions on S3 (
2025_01/03/05/06/08) are a release-pipeline issue and not fixable here.