-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add helper method to handle Debug.Fail #11270
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
Conversation
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.
+1
Will maybe want to have some way to skip the handling also if debugger is attached
Can you please elaborate? |
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.
👍
When in the debugger, you have to press continue several times for some reason, so it is unclear if you could ignore the exception. Outside the debugger, you get the dialog to connect to the debugger. None of these comments is against a merge as is. |
I am going to route consumed exceptions to the GitOutputControl in addition to to |
Debugger.Launch(); | ||
|
||
if (!Debugger.IsAttached) | ||
{ | ||
throw new InvalidOperationException(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.
This will prompt to attach a debugger, and if that's declined an exception will get routed to NBug... HOWEVER, if the code that triggered this was executing on a background thread it'd lead to the termination of the app.
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.
HOWEVER, if the code that triggered this was executing on a background thread it'd lead to the termination of the app.
It terminates the app but after starting the BugReporter, isn't it?
The goal is to not have background threads without exception handling. I assume that there is (almost) no such background operation left since the recent PR for JTF.RunAsync
and FileAndForget
.
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.
It terminates the app but after starting the BugReporter, isn't it?
Correct.
GitExtUtils/DebugHelpers.cs
Outdated
else if (!condition) | ||
{ | ||
Debugger.Launch(); | ||
|
||
if (!Debugger.IsAttached) | ||
{ | ||
throw new InvalidOperationException(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.
...the above makes me quite unhappy with this section. While nagging the dev in an invalid situation (guarded by Debug.Fail
) is warranted, it's not appropriate for a "check" situaion (i.e., Debug.Assert
) - an assert should not bring the app down.
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.
That's the fundamental problem with Debug.Assert
.
It is used for making assumptions explicit (good) - with the expectation that they will never fail.
(I see that these sanity checks are skipped in the release build for performance reasons.)
In most cases, it is wrong and unsafe to continue the execution. Sometimes, the code throws other exceptions. In many cases, it is just a lack of error handling in release builds (which is bad IMO).
db0d497
to
65f5df1
Compare
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.
LGTM
Debugger.Launch(); | ||
|
||
if (!Debugger.IsAttached) | ||
{ | ||
throw new InvalidOperationException(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.
HOWEVER, if the code that triggered this was executing on a background thread it'd lead to the termination of the app.
It terminates the app but after starting the BugReporter, isn't it?
The goal is to not have background threads without exception handling. I assume that there is (almost) no such background operation left since the recent PR for JTF.RunAsync
and FileAndForget
.
GitExtUtils/DebugHelpers.cs
Outdated
else if (!condition) | ||
{ | ||
Debugger.Launch(); | ||
|
||
if (!Debugger.IsAttached) | ||
{ | ||
throw new InvalidOperationException(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.
That's the fundamental problem with Debug.Assert
.
It is used for making assumptions explicit (good) - with the expectation that they will never fail.
(I see that these sanity checks are skipped in the release build for performance reasons.)
In most cases, it is wrong and unsafe to continue the execution. Sometimes, the code throws other exceptions. In many cases, it is just a lack of error handling in release builds (which is bad IMO).
65f5df1
to
8c2d9cb
Compare
MC resolved |
Thank you
|
No description provided.