fix: raise instead of return HTTPBadRequest on JSON decode error in compass_svc#45
Open
fix: raise instead of return HTTPBadRequest on JSON decode error in compass_svc#45
Conversation
create_adversary_from_layer() was returning web.HTTPBadRequest() on JSONDecodeError instead of raising it. In aiohttp, HTTP exception objects must be raised to be sent to the client; returning them causes the handler to return None, resulting in a 500 error instead of the intended 400.
There was a problem hiding this comment.
Pull request overview
Fixes create_adversary_from_layer() in app/compass_svc.py to correctly signal client errors to aiohttp by raising web.HTTPBadRequest when JSON parsing fails, instead of returning the exception object.
Changes:
- Replace
return web.HTTPBadRequest()withraise web.HTTPBadRequest()in theJSONDecodeErrorhandler.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
deacon-mp
added a commit
that referenced
this pull request
Mar 16, 2026
Adds 77 tests covering all public methods and endpoints in compass_svc.py and hook.py. Includes shared fixtures in conftest.py, edge cases for malformed/empty layers, missing fields, the raise-vs-return HTTPBadRequest inconsistency (PR #45), and stub auth_svc for isolated testing.
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
create_adversary_from_layer()incompass_svc.pywas returningweb.HTTPBadRequest()when aJSONDecodeErrorwas caught, instead of raising it.Before:
After:
Impact
In aiohttp, HTTP exception objects must be raised to be intercepted by the framework and sent as an HTTP response. When the exception object is returned instead, aiohttp receives
Nonefrom the handler (since the function continues past the return), resulting in a 500 Internal Server Error being returned to the client instead of the intended 400 Bad Request.Any client that submits a malformed or non-JSON layer file to the
create_adversary_from_layerendpoint receives a misleading 500 error rather than a clear 400 error indicating a client-side problem.Note: the
except Exceptionblock at the bottom of the same function correctly usesraise web.HTTPBadRequest()— this fix makes theJSONDecodeErrorpath consistent.Test plan