Property error handling - #389
Merged
Merged
Conversation
Barecheck - Code coverage reportTotal: 97.34%Your code coverage diff: 0.02% ▴ Uncovered files and lines
|
julianstirling
approved these changes
Aug 5, 2026
bprobert97
reviewed
Aug 6, 2026
This ought to be a helpful way to check when I've improved the error handling in properties. This is in response to #386. Unfortunately, too many of these tests already pass: this is an annoying artifact of the way TestClient is implemented.
This commit adds a decorator that provides a catch-all exception handler. If an exception occurs in a decorated function, it will log, and return a JSONResponse containing a ProblemDetails object, with an appropriate status code. This new wrapper is then used to ensure errors that occur in property get/set/reset functions are properly logged and a sensible HTTP response is given to the user. This needs testing explicitly in `test_problemdetails.py` and also needs tests fixing in `test_property_errors.py`.
This is required by new error handling code in properties.
Previously, setting a property didn't return a response. I changed this to return an empty response, which then caused errors in ThingClient. I've now changed this to return a JSONResponse with a value of `None`. I believe this matches the previous behaviour, and fixes the test failures.
I've run this test on both this branch and `main` to check that the response is identical.
I added a __name__ == "__main__" block for manual testing during development - this is no longer needed.
This adds a base level of unit testing for resetting properties.
Co-authored-by: Beth <167304066+bprobert97@users.noreply.github.com>
Thanks to @julianstirling for pointing out my inconsistent snake case before it hit `main`.
rwb27
force-pushed
the
property-error-handling
branch
from
August 6, 2026 08:55
ec4d00d to
10a5b3a
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.
This builds on the improved error handling for Actions in #333 and #370 to also handle errors in property getter/setter code. Things added by this PR:
Responseobject containingProblemDetailsdescribing the error.An incidental change is that setting or resetting a property now returns a
ResponsecontainingNone, rather than returningNonedirectly. I believe this is not a change in behaviour, but it keeps things consistent and means my type hints make sense. I added a test for resetting properties as well, as I made the same change to that function.Things to do before merging:
problem_detailsCloses #386
Closes #391