Skip to content

fix(cli): handle non-UTF-8 source files - #61

Open
xuu33030 wants to merge 1 commit into
alphacrack:mainfrom
xuu33030:fix/issue-27-non-utf8-cli
Open

xuu33030 wants to merge 1 commit into
alphacrack:mainfrom
xuu33030:fix/issue-27-non-utf8-cli

Conversation

@xuu33030

Copy link
Copy Markdown

Summary

Handle invalid UTF-8 and file-read failures before linting or executing a .dmai source file. Invalid encodings now produce a concise Maithili message and dedicated exit code instead of a raw Python traceback.

Motivation / Audit Reference

Closes #27.

Test Evidence

  • pytest -v --cov=maithili_dsl --cov-report=term-missing — 162 passed, 95.00% total coverage; cli.py 97%
  • New CLI and security regression tests cover invalid UTF-8 input
  • All example programs smoke-tested; error.dmai failed as expected
  • python -m maithili_dsl --version reports 0.4.0
  • Real subprocess verification returned exit code 7, printed the Maithili UTF-8 error, and emitted no traceback

Security Considerations

The file is still read before any linting, transpilation, import validation, or execution. Malformed input now fails closed at that boundary. The generic OSError message does not expose local path or exception details.

Breaking Changes

None. Valid UTF-8 programs retain their existing behavior and exit codes. Invalid encodings now have the documented non-zero EXIT_BAD_ENCODING code instead of an uncaught exception.

Checklist

  • CHANGELOG.md updated (Unreleased section)
  • Version bumped if this is a release PR (not applicable)
  • No new runtime dependencies added
  • User-visible error behavior documented in CHANGELOG.md

@alphacrack alphacrack left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, and the tests are clear. A few notes:

  • maithili_dsl/cli.py:126-128: every OSError (PermissionError, IsADirectoryError when a directory is passed, and so on) returns EXIT_NOT_FOUND (3) even though the path exists, which is misleading for scripts that check exit codes. Consider a separate EXIT_READ_ERROR and updating test_unreadable_file_returns_not_found to match.
  • CHANGELOG.md:11: please mention the new exit code 7 (EXIT_BAD_ENCODING), since it's a public CLI contract change.
  • Nit: tests/test_security.py:25: EXIT_BAD_ENCODING breaks the alphabetical import order.

What blocks the merge: the protect-main ruleset requires the ci-ok status check, which has never reported for this PR. The only CI run for d51ccbf (run 35372204218, 2026-09-18) failed with zero jobs, so the workflow never actually started. The branch is also 2 commits behind main.

To unblock: merge or rebase main into the branch (or push any new commit) so CI runs again. The maintainer may need to approve the fork run, and ci-ok then has to pass. No approving review is required by the ruleset.

This branch has not been deployed

No deployments
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.

[BUG] CLI crashes with raw traceback on non-UTF-8 .dmai files

2 participants