-
-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: on_operation hooks unable to modify result on error. #3629
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
29532a6
fix: on_operation hooks unable to modify result on error.
nrbnlulu d9ad3da
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] be9b16f
Add release file
patrick91 d1e46bf
Fix issue preventing extensions from receiving result in async execut…
nrbnlulu 0356d4f
Merge remote-tracking branch 'origin/fix-mask-error' into fix-mask-error
nrbnlulu 06c217b
delegate missing query error
nrbnlulu 699bd61
use the previous catch mechanism
nrbnlulu 1356171
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a658991
cherrypick execution logic for the mask error extension
nrbnlulu 6a5fc0c
Merge remote-tracking branch 'origin/fix-mask-error' into fix-mask-error
nrbnlulu 9f285c7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0f97717
ugly fix for assuring process errors is called exactly once.
nrbnlulu 951f88e
Merge remote-tracking branch 'origin/fix-mask-error' into fix-mask-error
nrbnlulu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,28 @@ def hidden_error(self) -> str: | |
] | ||
|
||
|
||
|
||
async def test_mask_all_errors_async(): | ||
@strawberry.type | ||
class Query: | ||
@strawberry.field | ||
def hidden_error(self) -> str: | ||
raise KeyError("This error is not visible") | ||
|
||
schema = strawberry.Schema(query=Query, extensions=[MaskErrors()]) | ||
|
||
query = "query { hiddenError }" | ||
|
||
result = await schema.execute(query) | ||
assert result.errors is not None | ||
formatted_errors = [err.formatted for err in result.errors] | ||
assert formatted_errors == [ | ||
{ | ||
"locations": [{"column": 9, "line": 1}], | ||
"message": "Unexpected error.", | ||
"path": ["hiddenError"], | ||
} | ||
] | ||
patrick91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test_mask_some_errors(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Consider adding an async version of test_mask_some_errors To maintain consistency and ensure both sync and async paths are tested equally, it would be beneficial to add an async version of the test_mask_some_errors test case.
|
||
class VisibleError(Exception): | ||
pass | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider restructuring the code to reduce nesting and improve readability.
The restructuring has increased code complexity by adding an extra level of nesting. While this change might have been intended to ensure proper closure of the context manager, it can be achieved without increasing the nesting level. Consider using a try-finally block to maintain the original structure while ensuring the context manager is always exited properly:
This approach maintains the original structure, reduces nesting, and ensures proper closure of the context manager in all cases, including when exceptions occur.