fix: make module map generation survive per-file syntax errors#226
Merged
fix: make module map generation survive per-file syntax errors#226
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ast.parse()calls intry/except SyntaxErrorinside a new_parse_modules()helper so a single broken module no longer aborts the entire map refreshParseErrorTypedDict tonightshift/core/types.pyand aparse_errors: list[ParseError]field toModuleMapSnapshot## Parse Errorssection in the markdown output listing each failed module and its error message; the section is omitted entirely when there are no errorsParseErrorfromnightshift/__init__.pyTest plan
test_generate_module_map_survives_per_file_syntax_error-- snapshot excludes broken module,parse_errorshas one entry with correct module nametest_generate_module_map_no_parse_errors_when_all_valid--parse_errorsis empty on a clean repotest_render_module_map_includes_parse_errors_section-- rendered markdown contains## Parse Errorsand the broken filenametest_render_module_map_omits_parse_errors_section_when_clean-- no## Parse Errorsin clean outputtest_module_map_cli_write_succeeds_with_syntax_error-- CLI returns exit code 0 and writes the errors section to filemake checkpasses (ruff, mypy, pytest, dry-runs, ASCII check)