-
Notifications
You must be signed in to change notification settings - Fork 515
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
[nnyeah] Centralize error handling #15064
Conversation
- Due to microsoft/vstest#3658 it is not possible to test code that exits the process on error - Create a base class for nnyeah exceptions that we want to explicitly report (and not crash), ConversionException - Move Main to Main2 and wrap it in a try/catch for this exception - I did not catch everything as for now I want to crash with stack trace on unexpected failures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more reason Environment.Exit
is evil 👿
catch (ConversionException c) { | ||
Console.Error.WriteLine (c.Message); | ||
return 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to catch all exceptions too, otherwise the process will exit with a very ugly message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I wasn't sure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add the following, do catch our base exception, then catch all exceptions and do a console.writeline with the message and then the url to provide an issue. If we got an unexpected exception it should be a bug/issue just like we do in xamarin.
else { | ||
ProcessAssembly (xamarinAssembly!, microsoftAssembly!, infile!, outfile!, verbose, forceOverwrite, suppressWarnings); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you changed this method to return the exit code, you won't need this change, you can just return 0;
after PrintOptions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that before. I felt that showing the flow as explicit "if show help do that, else do all of the processing" was better than an early return.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's more of a style choice, either way is fine with me.
Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
else { | ||
ProcessAssembly (xamarinAssembly!, microsoftAssembly!, infile!, outfile!, verbose, forceOverwrite, suppressWarnings); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's more of a style choice, either way is fine with me.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
catch (ConversionException c) { | ||
Console.Error.WriteLine (c.Message); | ||
return 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add the following, do catch our base exception, then catch all exceptions and do a console.writeline with the message and then the url to provide an issue. If we got an unexpected exception it should be a bug/issue just like we do in xamarin.
I split uncaught exception and conversion exception, and print the full stack trace and a generic "file an issue" message for uncaught now:
vs
|
💻 [PR Build] Tests on macOS Mac Catalina (10.15) passed 💻✅ All tests on macOS Mac Catalina (10.15) passed. Pipeline on Agent |
❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌Failed tests are:
Pipeline on Agent |
📋 [PR Build] API Diff 📋API diff (for current PR)ℹ️ API Diff (from PR only) (please review changes) .NETXamarin vs .NETAPI diff (vs stable)✅ API Diff from stable .NETXamarin vs .NETGenerator diff✅ Generator Diff (no change) Pipeline on Agent XAMBOT-1100.Monterey' |
dotnet test
crashes withSystem.Exception: Unable to read beyond the end of the stream
if code under tests callsSystem.Environment.Exit
microsoft/vstest#3658 it is not possible to test code that exits the process on errorI did not catch everything as for now I want to crash with stack trace on unexpected failures