Property error handling - #389
Open
rwb27 wants to merge 9 commits into
Open
Conversation
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.
Barecheck - Code coverage reportTotal: 97.33%Your code coverage diff: 0.02% ▴ Uncovered files and lines
|
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.
rwb27
marked this pull request as ready for review
August 3, 2026 23:06
This adds a base level of unit testing for resetting properties.
julianstirling
approved these changes
Aug 5, 2026
| ReturnT = TypeVar("ReturnT", bound=Response) | ||
|
|
||
|
|
||
| def exceptions_to_problemdetails( |
Contributor
There was a problem hiding this comment.
Not important but it seems funny to snake_case for most of this but not for problemdetails
Collaborator
Author
There was a problem hiding this comment.
that's a good point. I'll change that for consistency. I don't think that merits rereview.
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