Skip to content

fix(config): handle directory and non-UTF-8 wind definition inputs - #169

Merged
CameronBrooks11 merged 1 commit into
mainfrom
fix/loader-handles-dir-and-binary
Jun 25, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
fix/loader-handles-dir-and-binary

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

Bug B4 (loader half) from the latent-bug audit — covers the plan/validate paths (API + CLI).

Problem

load_wind_definition only caught json.JSONDecodeError and ValidationError. The read_text(encoding="utf-8") call itself can raise:

  • IsADirectoryError (an OSError) when the path is a directory, and
  • UnicodeDecodeError on a binary / non-UTF-8 file.

Neither is WindFileError, so the API returned HTTP 500 for /plan/from-file and /validate/from-file, and the CLI printed a raw traceback, for ordinary bad input.

Fix

Wrap the read and map (OSError, UnicodeDecodeError) to WindFileError — the same error the API maps to 4xx and the CLI maps to a clean BadParameter.

TDD

  • RED: ..._on_directory_raises_windfileerror (raw IsADirectoryError) and ..._on_non_utf8_file_raises_windfileerror failed before the fix.
  • GREEN: pass after. Full suite 125 passed, ruff/format/mypy clean.

Follow-up (B4b): the simulate route and the simulate/plot/stream CLI commands read G-code files via read_text directly (not through this loader) and have the same gap — handled in a separate PR.

load_wind_definition only caught JSONDecodeError and ValidationError, so a
directory path raised IsADirectoryError and a binary/non-UTF-8 file raised
UnicodeDecodeError straight out of read_text. The API surfaced these as
HTTP 500 (instead of 4xx) and the CLI as a raw traceback. Wrap the read and
map OSError/UnicodeDecodeError to WindFileError, which callers already handle.
Adds regression tests for a directory and a non-UTF-8 file.
@CameronBrooks11
CameronBrooks11 merged commit 0167685 into main Jun 25, 2026
18 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/loader-handles-dir-and-binary branch June 25, 2026 21:25
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