Skip to content

fix: make module map generation survive per-file syntax errors#226

Merged
fazxes merged 2 commits intomainfrom
fix/0108-module-map-syntax-resilience
Apr 9, 2026
Merged

fix: make module map generation survive per-file syntax errors#226
fazxes merged 2 commits intomainfrom
fix/0108-module-map-syntax-resilience

Conversation

@fazxes
Copy link
Copy Markdown
Member

@fazxes fazxes commented Apr 9, 2026

Summary

  • Wrap per-file ast.parse() calls in try/except SyntaxError inside a new _parse_modules() helper so a single broken module no longer aborts the entire map refresh
  • Add ParseError TypedDict to nightshift/core/types.py and a parse_errors: list[ParseError] field to ModuleMapSnapshot
  • Render a ## Parse Errors section in the markdown output listing each failed module and its error message; the section is omitted entirely when there are no errors
  • Export ParseError from nightshift/__init__.py

Test plan

  • test_generate_module_map_survives_per_file_syntax_error -- snapshot excludes broken module, parse_errors has one entry with correct module name
  • test_generate_module_map_no_parse_errors_when_all_valid -- parse_errors is empty on a clean repo
  • test_render_module_map_includes_parse_errors_section -- rendered markdown contains ## Parse Errors and the broken filename
  • test_render_module_map_omits_parse_errors_section_when_clean -- no ## Parse Errors in clean output
  • test_module_map_cli_write_succeeds_with_syntax_error -- CLI returns exit code 0 and writes the errors section to file
  • make check passes (ruff, mypy, pytest, dry-runs, ASCII check)

fazxes added 2 commits April 8, 2026 21:40
Wrap per-file ast.parse() in try/except SyntaxError so a single broken
module no longer aborts the entire map refresh. Failed modules are
recorded in a new ParseError TypedDict and surfaced as a "## Parse
Errors" section in the rendered markdown output. Regression tests cover
the resilience path and the no-error path.
SyntaxError alone was insufficient: path.read_text(encoding="utf-8")
raises UnicodeDecodeError for files with invalid UTF-8 bytes, which
is a ValueError subclass and not caught by the existing except clause.
Extend the handler to (SyntaxError, UnicodeDecodeError) so corrupted
source files are recorded in parse_errors instead of aborting
generate_module_map(). Adds a regression test using raw invalid bytes.
@fazxes fazxes merged commit 31e08e5 into main Apr 9, 2026
7 checks passed
@fazxes fazxes deleted the fix/0108-module-map-syntax-resilience branch April 9, 2026 01:49
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