mansenfranzen / autodoc_pydantic

Seamlessly integrate pydantic models in your Sphinx documentation.
MIT License
159 stars 27 forks source link

fix: Improve error message for `_sort_summary_list` failures #243

Closed mansenfranzen closed 7 months ago

mansenfranzen commented 7 months ago

Type

bug_fix


Description


Changes walkthrough

Relevant files
Error handling
autodocumenters.py
Enhanced Error Handling and Messaging in `_sort_summary_list`

sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py
  • Improved error handling in _sort_summary_list by adding a try-except
    block.
  • Enhanced the error message for exceptions during sorting, including
    the model name and sort order.
  • +7/-7     

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    github-actions[bot] commented 7 months ago

    PR Description updated to latest commit (https://github.com/mansenfranzen/autodoc_pydantic/commit/055db00e60282113c63155d12d4b5f5b1442f1b7)

    github-actions[bot] commented 7 months ago

    PR Review

    ⏱️ Estimated effort to review [1-5] 2, because the changes are localized to a specific function within a single file, focusing on error handling improvements. The logic seems straightforward, but understanding the context of the error handling and ensuring the new messages are clear and useful requires some domain knowledge.
    🧪 Relevant tests No
    🔍 Possible issues Possible Bug: The error message construction in the `except` block may miss a space between 'model' and the model name (`{self.object_name}`), which could lead to a concatenated string that is hard to read.
    🔒 Security concerns No
    Code feedback:
    relevant filesphinxcontrib/autodoc_pydantic/directives/autodocumenters.py
    suggestion       Consider adding a space before `{self.object_name}` in the error message to ensure proper readability of the output. [important]
    relevant linef'{self.object_name} with sort order {sort_order}.'


    ✨ Review tool usage guide:
    **Overview:** The `review` tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be [added](https://pr-agent-docs.codium.ai/tools/review/#general-configurations) by configuring the tool. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on any PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L23) related to the review tool (`pr_reviewer` section), use the following template: ``` /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_reviewer] some_config1=... some_config2=... ``` See the review [usage page](https://pr-agent-docs.codium.ai/tools/review/) for a comprehensive guide on using this tool.
    github-actions[bot] commented 7 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Add a space for readability in the error message. ___ **The error message for the TypeError exception does not include a space between 'model' and
    the model name (self.object_name). Adding a space will improve the readability of the
    error message.** [sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py [577-578]](https://github.com/mansenfranzen/autodoc_pydantic/pull/243/files#diff-7d73b320876bd66b008302d189d9a4550cfa334ade88a74e80a3405797e32192R577-R578) ```diff -f'Uncaught exception while sorting fields for model' +f'Uncaught exception while sorting fields for model ' f'{self.object_name} with sort order {sort_order}.' ```
    Include the original exception message for more detailed error context. ___ **To provide more context in the error message when a TypeError is raised during sorting,
    it's helpful to include the original exception message (e) along with the custom error
    message. This can aid in debugging by providing more detailed information about the root
    cause of the error.** [sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py [576-580]](https://github.com/mansenfranzen/autodoc_pydantic/pull/243/files#diff-7d73b320876bd66b008302d189d9a4550cfa334ade88a74e80a3405797e32192R576-R580) ```diff msg = ( f'Uncaught exception while sorting fields for model ' - f'{self.object_name} with sort order {sort_order}.' + f'{self.object_name} with sort order {sort_order}. Exception: {e}' ) raise ValueError(msg).with_traceback(e.__traceback__) from e ```

    ✨ Improve tool usage guide:
    **Overview:** The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.
    codecov-commenter commented 7 months ago

    Codecov Report

    Attention: Patch coverage is 50.00000% with 2 lines in your changes are missing coverage. Please review.

    Project coverage is 94.26%. Comparing base (461be30) to head (055db00).

    Files Patch % Lines
    ...rib/autodoc_pydantic/directives/autodocumenters.py 50.00% 2 Missing :warning:
    Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #243 +/- ## ========================================== - Coverage 94.34% 94.26% -0.08% ========================================== Files 12 12 Lines 1114 1116 +2 ========================================== + Hits 1051 1052 +1 - Misses 63 64 +1 ```

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.