Skip to content

feat: improve CLI and web API validation with clearer runtime errors#8

Merged
rad1092 merged 2 commits into
mainfrom
codex/start-project-according-to-readme.md
Feb 13, 2026
Merged

feat: improve CLI and web API validation with clearer runtime errors#8
rad1092 merged 2 commits into
mainfrom
codex/start-project-according-to-readme.md

Conversation

@rad1092
Copy link
Copy Markdown
Owner

@rad1092 rad1092 commented Feb 13, 2026

Motivation

  • Improve usability and robustness by surfacing clear, user-facing errors for common operator mistakes like missing CSV files and malformed API parameters.
  • Harden the local UI API against abusive or accidental inputs by validating timeout values and CSV payload sizes to avoid confusing runtime failures.

Description

  • Convert analysis failures into a friendly exit message in the CLI by catching AnalysisError and FileNotFoundError in run_analyze and raising SystemExit with analysis error: ... instead of a raw traceback (bitnet_tools/cli.py).
  • Add stricter timeout parsing and bounds checking for the web API POST /api/run so non-integer timeout values are rejected and values outside 1..600 seconds return a clear HTTP error (bitnet_tools/web.py).
  • Add a regression test to assert the CLI path for a missing CSV file fails with a clear SystemExit message and expand tests exercising CSV parsing and summarization (tests/test_analysis.py).

Testing

  • Ran unit tests with python -m pytest -q, which returned 6 passed.
  • Verified CLI behavior with python -m bitnet_tools.cli analyze /tmp/does-not-exist.csv --question '점검' --out /tmp/nope.json, which exited with a friendly analysis error: CSV file not found and non-zero status.
  • Performed a web API smoke test by POSTing an invalid timeout (e.g. `

Codex Task

@rad1092 rad1092 merged commit ca57ede into main Feb 13, 2026
0 of 4 checks passed
@chatgpt-codex-connector
Copy link
Copy Markdown

💡 Codex Review

"std": float(pstdev(values)) if len(values) > 1 else 0.0,

P1 Badge Guard numeric stats against NaN/Infinity inputs

Values like NaN or inf are accepted as numeric and flow into summary statistics, but statistics.pstdev fails on non-finite numbers (ValueError/OverflowError), which crashes analysis for otherwise common CSV markers. This means build_analysis_payload can terminate with a traceback instead of returning a user-facing analysis error whenever a numeric column includes these tokens.


content_length = int(self.headers.get("Content-Length", "0"))

P2 Badge Validate Content-Length before converting to int

do_POST converts Content-Length with int(...) outside the request-validation try blocks, so a malformed header such as Content-Length: abc raises ValueError and aborts the handler thread instead of returning a 4xx JSON error. This makes malformed requests bypass the API's intended error handling path and produce server-side exceptions.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant