Skip to content
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

DYN-6492 add unhandled exception handler to viewmodel #14840

Merged
merged 4 commits into from
Jan 22, 2024

Conversation

aparajit-pratap
Copy link
Contributor

Purpose

Subscribe to Application.DispatcherUnhandledException event to handle unhandled exceptions coming from external code like extensions. This PR basically takes the work done in #14826 by @pinzart90 and moves it to the ViewModel so it isn't specific to sandbox.

WIP for some initial feedback.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB

Release Notes

(FILL ME IN) Brief description of the fix / enhancement. Mandatory section

FYIs

(FILL ME IN, Optional) Names of anyone else you wish to be notified of

@aparajit-pratap aparajit-pratap changed the title [WIP] add unhandled exception handler to viewmodel [WIP] DYN-6492 add unhandled exception handler to viewmodel Jan 12, 2024
Copy link

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

Copy link

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

@@ -675,6 +675,8 @@ public static DynamoViewModel Start(StartConfiguration startConfiguration = new

protected DynamoViewModel(StartConfiguration startConfiguration)
{
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pinzart90 does it make sense to also subscribe to the appdomain exception event here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure where we should put this handler. Theoretically it should be added as soon as possible in the application lifecycle so that more exceptions can be handled.
Also this handler will not catch exceptions coming from other threads. THat is where AppDomain.UNhandledException would come in handy. However it seems a bit risky since it could be called in non UI threads (at least that's what I;ve noticed in my testing)

return;
}

e.Handled = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Marking it as handled will mean other handlers will no longer be called anymore. Ex D4R will exception Handler will no longer be called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, as discussed, this needs some design so host-specific shutdown/cleanup steps can be taken into account in this handler. WIP.

Copy link
Contributor Author

@aparajit-pratap aparajit-pratap Jan 18, 2024

Choose a reason for hiding this comment

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

I checked, and marking it as handled does not mean that other handlers will not be called. The Revit unhandled exception handler will still be called, the only thing is that the value of e.Handled will be true before it's called, which means we can check its value to decide if we want to skip any redundant steps that have already completed here such as logging to analytics, displaying the crash dialogs, etc.

Correction: I was wrong about the previous comment. I saw the handler in D4R being called earlier since another exception was being thrown while the exception was being handled in DynamoViewModel while shutting down Dynamo and this call wasn't within the try-catch. I have now moved this within the try-catch in the handler as well. According to the docs, Event handlers for this event must be written with care to avoid creating secondary exceptions and to catch any that occur.

I have removed the same handler from D4R, see my PR in DynamoRevit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, looks like there is another handler that can mark exceptions as “handled” https://learn.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatcher.unhandledexceptionfilter?view=windowsdesktop-8.0

not sure what we could do with it(or how to use it). Maybe mark dynamo VM exceptions as handled so the app just continues and we only log(somehow). Probably for another time..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VM exceptions are usually non-recoverable. They are signs of the VM being corrupt most of the time so it's wise to shutdown and restart Dynamo in those cases. Still worth taking a look at this. Thanks.

Copy link

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

@pinzart90
Copy link
Contributor

@aparajit-pratap maybe we should also check what civil is doing for handling exceptions and make sure this change is compatible

@aparajit-pratap
Copy link
Contributor Author

@aparajit-pratap maybe we should also check what civil is doing for handling exceptions and make sure this change is compatible

@pinzart90 I checked, and it doesn't look like civil is doing any exception handling like this or like the one being done in D4R.

Copy link

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

@aparajit-pratap aparajit-pratap changed the title [WIP] DYN-6492 add unhandled exception handler to viewmodel DYN-6492 add unhandled exception handler to viewmodel Jan 19, 2024
@aparajit-pratap aparajit-pratap merged commit f7ec0d8 into DynamoDS:master Jan 22, 2024
21 checks passed
@aparajit-pratap aparajit-pratap deleted the dyn-6492 branch January 22, 2024 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants