Keep PathAccessError printable for Scope/S paths (#249)#298
Merged
Conversation
76c2d0b to
da92fe0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #298 +/- ##
==========================================
- Coverage 98.25% 98.22% -0.04%
==========================================
Files 27 27
Lines 4364 4384 +20
Branches 612 612
==========================================
+ Hits 4288 4306 +18
- Misses 52 53 +1
- Partials 24 25 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
539abb1 to
8c8f395
Compare
Owner
|
This is a really good catch. I think I found a slightly simpler approach since all |
8c8f395 to
ec70055
Compare
PathAccessError.get_message() called Path(self.path) which re-wraps an already-Path object. For S-rooted paths, Path() rejects the S root with ValueError, crashing __str__ and producing '<exception str() failed>'. Fix: call self.path.values() directly — self.path is already a Path at every call site. Keep a lightweight AttributeError/IndexError fallback for safety in case of unexpected .path types. Test asserts the message content (key name, part index, error type), not just that it doesn't crash.
ec70055 to
7583a20
Compare
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 #249.
A
PathAccessErrorraised from aScope/Saccess cannot stringify itself —str(exc)renders as<exception str() failed>:Cause
PathAccessError.get_message()doesPath(self.path).values()[self.part_idx]. When the access originates from a scope,self.pathis not a plainT-based path, andPath(...)raisesValueError: path segment must be path from T, not S. Becauseget_message()is called fromGlomError.__str__, that exception escapes and the error can no longer be printed (andget_message()itself crashes).Fix
Guard the
Path(self.path)lookup and fall back toself.pathwhen it can't be turned into a plain path, so the message stays readable instead of raising:An exception should always be able to produce a string and never crash its own formatter, so this restores the documented "readable error message" contract for the
S/scope case without changing the normalT-path output.Tests
Added
test_pae_scope_printableinglom/test/test_error.py, asserting the scope-originatedPathAccessErroris printable (no<exception str() failed>) and thatget_message()returns a string. It is RED without the fix and GREEN with it. The error and scope suites pass (test_error.py,test_scope_vars.py: 27 passed); the only failing tests in the repo are pre-existingtest_cli.pyenvironment failures unrelated to this change.Disclosure: I prepared this fix with AI assistance under my direction; I reviewed and verified the change and the test myself.