-
-
Notifications
You must be signed in to change notification settings - Fork 811
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
Incomplete stack trace when exceptions when raising events #738
Comments
This should remove information that is valuable only when Moq is malfunctioning. The general idea here is to give you a short stack trace pointing at your code, and to spare you stack frames that represent purely Moq internals, which are going to be uninteresting for most users. (I do think the original exception should be preserved e.g. as an What additional information are you hoping for? What scenario made you say that your stack trace contains no information? |
It is quite clumsy to debug user code code executed by Moq. If an exception is thrown in the following code, the stack trace is
The site throwing the exeption is lost. The debugger does not break on the exception by default because it is not an uncaught exception. Putting the exception into an inner exception seems bad too unless the enclosing exception is a smart exception which prints the all user code stack trace. Setup.().CallBack() and I suspect other places also suffers from this symptom too. |
@MutatedTomato: Could you please post a complete code example? I'm not sure I understand the above example correctly. |
Closing due to a lack of response. Until we get a clearer idea how the stack trace would be more helpful if it showed Moq internal method calls instead of being truncated at Moq's public API boundary, the main takeaway for me here will be that instead of just throwing away the full stack trace, it should at least be preserved via |
All test cases below allow you to click one the stacktrace to locate the exception quickly but not TestEventException. There is noise in the TestCallbackException but it is better than no information. I cannot reproduce the problem of no automatic breaking on unhandled exceptions. Unfortunately, I am too busy to investigate now.
|
Thanks for posting these tests, I'll check them out soon. |
@MutatedTomato - I see. I'd say we remove the catches and throws, just like you said in your initial post. - try
- {
target.DoRaise(ev, args);
- }
- catch (Exception e)
- {
- // Reset stack trace so user gets this call site only.
- throw e;
- } We've internally moved to use Feel free to submit a PR for this, if you wish. Since you're currently busy, I'll wait for a few days, but if I don't hear from you, I'll take the liberty of applying the changes. |
Nice and thx. Please apply it yourself. Don't wait for me. |
When raising an event which throws an exception, the stack trace is terminated at
Raise
. In Mock.Generic.cs around line 571Removing the try catch should give a full stack trace. There will be noise but there will also be useful information. It is much better than no information.
The text was updated successfully, but these errors were encountered: