Repository navigation
fix: narrow bare except Exception in version fallback - #3835
Open
Quratulain-bilal wants to merge 3 commits into
Open
Quratulain-bilal wants to merge 3 commits into
Quratulain-bilal wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Narrows exception handling in the Spec Kit version fallback.
Changes:
- Handles missing package metadata explicitly.
- Limits project-file errors to expected exception types.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/_assets.py |
Narrows version lookup fallback exceptions. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Medium
| try: | ||
| return importlib.metadata.version("specify-cli") | ||
| except Exception: | ||
| except importlib.metadata.PackageNotFoundError: |
Replace overly broad except Exception with specific exception types: - importlib.metadata.PackageNotFoundError for missing package - (OSError, KeyError, ValueError) for pyproject.toml read/parse errors This prevents silently swallowing unexpected errors like AttributeError or RecursionError from broken tomllib or malformed pyproject.toml.
Quratulain-bilal
force-pushed
the
fix/assets-narrow-exception
branch
from
July 29, 2026 20:33
fdb5353 to
56ea7d4
Compare
Contributor
|
This pull request has been automatically marked as stale because it has had no activity for 60 days. It will be closed in 30 days unless there is a substantive update. If you intend to continue, please describe the current status, address or acknowledge outstanding feedback, and confirm whether the branch can be updated and the change remains ready for review. A comment that only states that the pull request is "still relevant" does not provide enough context for maintainers. |
…allback importlib.metadata.version() can raise InvalidMetadataError for a malformed installed distribution, which is not a PackageNotFoundError, so the narrowed handler let it escape get_speckit_version() instead of using the pyproject/unknown fallback. Build the guarded exception tuple before the lookup, mirroring _version._get_installed_version(). The narrowed pyproject branch also called .get() on whatever the project key held, so a non-mapping value turned the fallback into an AttributeError; read it through isinstance checks instead. Regression tests cover both paths (corrupt metadata and a non-mapping project table) plus the pyproject fallback itself. Both new tests fail on the previous implementation: one with the escaping InvalidMetadataError, the other with AttributeError: 'int' object has no attribute 'get'. Assisted-by: opencode (model: mimo-v2.6-flash-free, autonomous)
Comment on lines
+25
to
+29
| def test_get_speckit_version_survives_invalid_metadata(monkeypatch): | ||
| """A corrupt installed distribution must fall back, not raise. | ||
|
|
||
| ``InvalidMetadataError`` is not a ``PackageNotFoundError``, so catching | ||
| only the latter lets it escape the version fallback (the same guard |
Collaborator
|
Please address Copilot feedback |
This branch has not been deployed
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
Replace overly broad
except Exceptionwith specific exception types inget_speckit_version()fallback.Changes
_assets.py: Narrow outer exception toPackageNotFoundError_assets.py: Narrow inner exception to(OSError, KeyError, ValueError)