Skip to content

fix(api): return 400 for empty G-code on the stream route - #171

Merged
CameronBrooks11 merged 1 commit into
mainfrom
fix/stream-empty-gcode-400
Jun 25, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
fix/stream-empty-gcode-400

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

Bug B5 from the latent-bug audit.

Problem

POST /stream/ with empty/whitespace-only gcode let iter_stream→load_program raise StreamError("...no commands"), which the handler maps to HTTP 502 (Bad Gateway). Empty client input is a 400, not an upstream-device failure.

Fix

Pre-check for any non-blank line before invoking the streamer and return 400. Genuine transport StreamErrors still map to 502.

TDD

  • RED: test_stream_route_empty_gcode_returns_400 got 502 before the fix.
  • GREEN: passes after. Full suite 129 passed, ruff/format/mypy clean.

Empty/whitespace-only gcode made load_program raise StreamError, which the
route mapped to HTTP 502 (Bad Gateway) — implying an upstream device failure
for what is plain client error. Pre-check for any non-blank line and return
400, leaving 502 for genuine transport StreamErrors. Adds a regression test.
@CameronBrooks11
CameronBrooks11 merged commit 48f6c91 into main Jun 25, 2026
12 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/stream-empty-gcode-400 branch June 25, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant