Skip to content

Conversation

@misrasaurabh1
Copy link
Contributor

@misrasaurabh1 misrasaurabh1 commented Jul 5, 2025

PR Type

Bug fix


Description

  • Wrap cst.parse_module(...).visit in try-except

  • Log parsing errors with logger.error

  • Return dst_module_code on parse failure


Changes walkthrough 📝

Relevant files
Error handling
code_extractor.py
Add exception guard to CST parser                                               

codeflash/code_utils/code_extractor.py

  • Wrapped cst.parse_module(src_module_code).visit(gatherer) in
    try-except
  • Logged exceptions during parsing with error level
  • Returned original dst_module_code on error to avoid crash
  • +5/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link

    github-actions bot commented Jul 5, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Broad exception

    Using a bare except Exception may suppress unexpected errors; consider catching more specific parsing exceptions (e.g., ParserSyntaxError) to avoid hiding unrelated bugs.

    try:
        cst.parse_module(src_module_code).visit(gatherer)
    except Exception as e:
    Limited logging

    The error log only records the exception message; include the stack trace by using logger.error(..., exc_info=True) for better troubleshooting.

    logger.error(f"Error parsing source module code: {e}")

    @github-actions
    Copy link

    github-actions bot commented Jul 5, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Restrict caught exception type

    Narrow the exception to only the CST parsing errors so unrelated bugs aren’t masked.

    codeflash/code_utils/code_extractor.py [329]

    -except Exception as e:
    +except cst.ParserSyntaxError as e:
    Suggestion importance[1-10]: 7

    __

    Why: Catching generic Exception can mask other issues, so narrowing to cst.ParserSyntaxError ensures only parse errors are handled.

    Medium
    General
    Include traceback in log

    Use logger.exception (or pass exc_info=True) to include the full traceback in the
    logs, aiding debugging.

    codeflash/code_utils/code_extractor.py [330]

    -logger.error(f"Error parsing source module code: {e}")
    +logger.exception(f"Error parsing source module code: {e}")
    Suggestion importance[1-10]: 6

    __

    Why: Using logger.exception (or exc_info=True) surfaces the full traceback, aiding debugging when parsing fails.

    Low
    Log filename for context

    Add the source filename to the log message for clearer context when multiple files
    are processed.

    codeflash/code_utils/code_extractor.py [330]

    -logger.error(f"Error parsing source module code: {e}")
    +logger.error(f"Error parsing {src_path.name}: {e}", exc_info=True)
    Suggestion importance[1-10]: 5

    __

    Why: Adding src_path.name gives clear context on which file failed, improving log clarity when processing multiple modules.

    Low

    @misrasaurabh1 misrasaurabh1 merged commit e56428e into main Jul 6, 2025
    16 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant