Skip to content

fix(api,cli): handle directory and non-UTF-8 G-code inputs - #170

Merged
CameronBrooks11 merged 1 commit into
mainfrom
fix/gcode-readers-handle-dir-and-binary
Jun 25, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
fix/gcode-readers-handle-dir-and-binary

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

Bug B4 (G-code-reader half) from the latent-bug audit — the simulate/plot/stream paths that read G-code directly (not via the wind loader fixed in #169).

Problem

  • API /simulate/from-file only checked target.exists(), then read_text(encoding="utf-8") raised IsADirectoryError (directory) or UnicodeDecodeError (binary) → unhandled HTTP 500.
  • CLI simulate/plot/stream declared the G-code arg as typer.Argument(..., exists=True, readable=True) — dir_okay defaults to True, so a directory passed validation and crashed in read_text with a raw traceback.

Fix

  • API: add an is_file() check (→ 400) and wrap the read, mapping (OSError, UnicodeDecodeError) → 400.
  • CLI: add file_okay=True, dir_okay=False to the three G-code arguments so typer rejects directories with a clean usage error (exit 2).

TDD

  • RED: API directory + binary tests returned 500; CLI directory test exited 1 with IsADirectoryError.
  • GREEN: all pass after. Full suite 128 passed (+3), ruff/format/mypy clean.

The simulate route only checked path existence, then read_text raised
IsADirectoryError (directory) or UnicodeDecodeError (binary) -> HTTP 500. The
simulate/plot/stream CLI args allowed directories (typer dir_okay defaults
true), leaking a raw traceback. Guard the API route with is_file() + a wrapped
read (400 on unreadable/non-UTF-8), and set dir_okay=False on the three CLI
G-code arguments so typer rejects directories with a clean usage error.
Adds regression tests for the API (directory, binary) and CLI (directory).
@CameronBrooks11
CameronBrooks11 merged commit 0e87887 into main Jun 25, 2026
18 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/gcode-readers-handle-dir-and-binary branch June 25, 2026 21:33
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