Handle exception chaining and groups in Dev's traceback handling #6178

Merged
Jackenmen merged 4 commits from handle_more_things_in_dev_traceback_handling into V3/develop 2023-06-22 01:42:02 +02:00
Jackenmen commented 2023-05-28 19:32:07 +02:00 (Migrated from github.com)

Description of the changes

Addresses issues with Dev's traceback formatting not including the code for chained/grouped exceptions:

  1. Formatting of exception chaining before:
try:
    1 / 0
except ZeroDivisionError as exc:
    try:
        raise RuntimeError("direct cause") from exc
    except RuntimeError as exc2:
        raise ValueError("direct cause 2")
Traceback (most recent call last):
  File "<eval command - snippet #0>", line 3, in func
ZeroDivisionError: division by zero

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<eval command - snippet #0>", line 6, in func
RuntimeError: direct cause

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<eval command - snippet #0>", line 7, in func
    raise ValueError("direct cause 2")
ValueError: direct cause 2
  1. Formatting of exception groups before:
def f(v):
    try:
        raise ValueError(v)
    except ValueError as e:
        return e

raise ExceptionGroup("one", [f(1)])
  + Exception Group Traceback (most recent call last):
  |   File "<eval command - snippet #0>", line 7, in <module>
  |     raise ExceptionGroup("one", [f(1)])
  | ExceptionGroup: one (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "<eval command - snippet #0>", line 3, in f
    | ValueError: 1
    +------------------------------------

On top of that, we now also update the SyntaxError.end_lineno with line_offset on Python 3.10.

Have the changes in this PR been tested?

Yes

### Description of the changes Addresses issues with Dev's traceback formatting not including the code for chained/grouped exceptions: 1. Formatting of exception chaining before: ```py try: 1 / 0 except ZeroDivisionError as exc: try: raise RuntimeError("direct cause") from exc except RuntimeError as exc2: raise ValueError("direct cause 2") ``` ``` Traceback (most recent call last): File "<eval command - snippet #0>", line 3, in func ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<eval command - snippet #0>", line 6, in func RuntimeError: direct cause During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<eval command - snippet #0>", line 7, in func raise ValueError("direct cause 2") ValueError: direct cause 2 ``` 2. Formatting of exception groups before: ```py def f(v): try: raise ValueError(v) except ValueError as e: return e raise ExceptionGroup("one", [f(1)]) ``` ``` + Exception Group Traceback (most recent call last): | File "<eval command - snippet #0>", line 7, in <module> | raise ExceptionGroup("one", [f(1)]) | ExceptionGroup: one (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "<eval command - snippet #0>", line 3, in f | ValueError: 1 +------------------------------------ ``` On top of that, we now also update the `SyntaxError.end_lineno` with `line_offset` on Python 3.10. ### Have the changes in this PR been tested? Yes
Jackenmen commented 2023-05-28 19:33:48 +02:00 (Migrated from github.com)

It is probably best to review this with hidden whitespace in diffs:
image

It is probably best to review this with hidden whitespace in diffs: ![image](https://github.com/Cog-Creators/Red-DiscordBot/assets/6032823/7451fc44-5ebb-4880-b4be-6fd5489138dd)
TrustyJAID (Migrated from github.com) approved these changes 2023-06-22 01:37:28 +02:00
TrustyJAID (Migrated from github.com) left a comment

This looks good to me

This looks good to me
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!6178
No description provided.