Repository navigation
fix(api): map core engine errors to 400 and cap stream payload - #112
Merged
Merged
Conversation
The plan and simulate routes let core-engine input errors escape as raw
HTTP 500s, unlike the CLI which treats them as clean user errors. Register
centralized FastAPI exception handlers in create_app() mapping PlanningError
(and its subclass LayerValidationError) and SimulationError to 400 with a
{"detail": ...} body. Centralizing in main.py is DRY, covers any future
route, and structurally fixes the missing SimulationError import in the
simulate route.
Also cap StreamRequest.gcode at 10_000_000 chars (pydantic max_length) so an
oversized payload is rejected with 422 rather than consuming unbounded memory.
Adds error-path tests: plan validation -> 400, empty program -> 400,
oversized stream payload -> 422.
Closes #104
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.
What
Map recoverable core-engine input errors in the API to HTTP 400 instead of letting them surface as raw 500s, and cap the
/streampayload size.Why
The plan and simulate routes called
plan_wind()/simulate_program()with no exception handling, so a bad-but-recoverable input (LayerValidationError,SimulationError) became an opaque 500. The CLI treats these as clean user errors; the API now matches.How
create_app()(main.py):add_exception_handlerforPlanningError(covers its subclassLayerValidationErrorvia isinstance dispatch) andSimulationError, both →400 {"detail": str(exc)}. Centralizing is DRY, covers any future route, and structurally fixes the previously-missingSimulationErrorimport in the simulate route (the route needs no change).WindFileError → 400convention (per maintainer decision).StreamRequest.gcodegetsmax_length=10_000_000(~10 MB, comfortably above realistic worst-case winding programs) so oversized payloads are rejected by request validation (422) rather than consuming unbounded memory.Verification
windAngleout of range), empty program → 400 (SimulationError), oversized stream payload → 422. Each asserts!= 500.ruff,ruff format --check,mypy(strict), fullpytest: all green (114 passed).Closes #104