Skip to content

Refactor Parser Error Handling #1172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 75 commits into
base: dev
Choose a base branch
from

Conversation

azaleacolburn
Copy link
Contributor

@azaleacolburn azaleacolburn commented Jun 26, 2025

Description

The synthesis parser in the exporter now properly handles the errors it was catching, instead of always printing the stacktrace to the user, it now displays clean errors in most cases. This PR also removes the logging wrapper that was previously being used essentially to wrap everything in a try-catch. Errors now propagate through the parser as values with a new Result class which is inspired by the Rust enum of the same name. Each error contains a message and a severity (Fatal or Warning), the latter refers to the severity on the entire parsing process, so an error might cause a function to completely fail, but the error can be recovered by a parent function. On instantiation, each Err automatically logs itself based on it's severity. For errors that are not even fatal for the originating function, an Err should be instantiated but not returned, as to not break control flow.

While some were obvious, for several functions, I wasn't entirely sure how/why they would fail (despite them being marked as fallible with logFailure), so for those ones, we'll need to switch to the Result-based error handling system as we find errors.

Objectives

  • Result implementation
  • Document Result, Err, and Ok classes
  • Replace old error handling with nicer alternative (both for the user and developer)
    • Components.py
    • Materials.py
    • JointHierarchy.py
    • Joints.py
    • PDMessage.py
    • PhysicalProperties.py
    • RigidGroup.py(unsure)
    • Utilities.py
  • Put checks after every opaque fusion function. This should probably be it's own PR.

Testing Done

  • Successfully exported Dozer

JIRA Issue

@azaleacolburn azaleacolburn self-assigned this Jun 26, 2025
@azaleacolburn azaleacolburn added exporter refactor The most important part of software development. labels Jun 26, 2025
@azaleacolburn azaleacolburn force-pushed the colbura/1858/parser-error-handling branch from 8171223 to 473f6f3 Compare June 30, 2025 15:12
@azaleacolburn azaleacolburn marked this pull request as ready for review June 30, 2025 15:15
@azaleacolburn azaleacolburn requested review from a team as code owners June 30, 2025 15:15
@autodesk-chorus
Copy link

Chorus detected one or more security issues with this pull request. See the Checks tab for more details.

As a reminder, please follow the secure code review process as part of the Secure Coding Non-Negotiable requirement.

@azaleacolburn azaleacolburn requested a review from a team as a code owner June 30, 2025 18:27
Copy link
Member

@BrandonPacewic BrandonPacewic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

In JointHierarchy.py there are still some exceptions that are following the old pattern:

if self.grounded is None:
gm.ui.messageBox("There is not currently a Grounded Component in the assembly, stopping kinematic export.")
raise RuntimeWarning("There is no grounded component")

This is causing the message box to display with the error AND the full traceback being showed to the user which was the previous behaviour of our logger. Not really sure how we should update this since it's within an init but we maybe could avoid showing the full traceback to the user and confirm that the export is actually being stopped as described by the messagebox.

@azaleacolburn
Copy link
Contributor Author

azaleacolburn commented Jul 10, 2025

Looking good.

In JointHierarchy.py there are still some exceptions that are following the old pattern:

if self.grounded is None:
gm.ui.messageBox("There is not currently a Grounded Component in the assembly, stopping kinematic export.")
raise RuntimeWarning("There is no grounded component")

This is causing the message box to display with the error AND the full traceback being showed to the user which was the previous behaviour of our logger. Not really sure how we should update this since it's within an init but we maybe could avoid showing the full traceback to the user and confirm that the export is actually being stopped as described by the messagebox.

Ya this is a tricky one. I think the way to go is to log the message (with the Err class), display a message box, then just remove the logging decorator and close the program quietly without logging the full traceback.

@azaleacolburn azaleacolburn force-pushed the colbura/1858/parser-error-handling branch from 14cc761 to a6e93fa Compare July 10, 2025 18:18
Copy link
Member

@BrandonPacewic BrandonPacewic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a change that reverted a PWM icon update as the file was being replaced with a question mark. I also merged dev and fixed some merge conflicts.

  1. It still looks like we are showing the full traceback upon a rigid component not being detected.
  2. I'm getting an issue where the file name of an exported design is starting with a v.
image

@azaleacolburn
Copy link
Contributor Author

It still looks like we are showing the full traceback upon a rigid component not being detected.
This is caused by the logFailure decorator around ConfigureCommandExecuteHandler.notify method, which initializes and calls the Parser. To fix this, I just put a try block around the Parser usage with an except block that just passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter refactor The most important part of software development.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants