-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
AggregateException.ToString() when wrapped in another exception loses data #28818
Comments
@hannasm I believe you can open MSTest questions and issues @ https://github.com/Microsoft/testfx |
As described in the SO link,
This is a problem with Exception itself. The same "information loss" occurs whenever the inner exception writes something in its ToString() that isn't included in its Message (or inner exceptions). Eg., var fle = new FileLoadException("<msg>", "<filename>");
Console.WriteLine(fle.ToString()) ;
Console.WriteLine("####");
var ex = new Exception("<exmsg>", fle);
Console.WriteLine(ex.ToString()); gives
Here you lost the filename (although it's likely not noticed in this case as the default message contains it). On SqlException, the ToString() has a lot more information that's not in the message, and one would expect it to not be lost. |
On Exception we have public override string ToString()
{
return ToString(true, true);
}
private string ToString(bool needFileLineInfo, bool needMessage)
{ ... }
// CoreCLR only
// InternalToString is called by the runtime to get the exception text.
internal string InternalToString()
{
// Get the current stack trace string.
return ToString(true, true);
} I guess the runtime uses But when someone calls One way to fix this would be to add another parameter |
cc @stephentoub Having looked at so many test failure callstacks in logs, I am pretty motivated to fix any case I found where the output is incomplete.. |
The current shape of this code was influenced by code-access-security (e.g. the overriden ToString could have been malicious), some kind of Watson feature (it was done for Silverlight - I am not sure whether it is still relevant) , and bug-for-bug .NET Framework compatibility bar.
I would rather look at whether we can fix this by deleting code. |
Makes sense. Looking at places that call through METHOD__EXCEPTION__INTERNAL_TO_STRING, they are all likely not concerned whether it calls ToString() directly instead. The one htat seems watson related is @leculver how do does Watson rely on the exception text (the result of ToString() or in this case InternalToString() on Exception)? Right now it uses the latter, which is oblivious to ToString() overrides, possibly a good thing if you simply must get the callstack that way and the ToString() hypothetically does not return it, but otherwise not necessarily a good thing as it can miss some interesting information. |
This is all if I remember correctly... The extra failfast argument here with an exception message was for Silverlight (and maybe phone?) so that customers could get this message directly/more easily. For desktop CLR I don't think this entire codepath exists, and bucketing seems fine without it. also for desktop, Watson generally inspects the shape of exception objects through functions like these. Right now, Watson is fairly broken on .Net Core for a variety of reasons. I don't think anyone in the Watson space is going to notice if we strip out all of this code around adding an extra bucket parameter for .Net Core. It's on my TODO list to make .Net Core Watson work better, and using this text string wouldn't be a part of that anyway. So in short: +1 to Jan's recommendation of "can we just strip out most of this code and make things better?" |
As noted in the linked issue, the same issue exists with |
When AggregateException is wrapped in another exception, the ToString() method no longer populates the complete list of exception details.
Full MSTest code:
Test003 (which does not wrap AggregateException) displays:
Test004 however, (which wraps AggregateException in an Exception) is missing the details on "Exception 2"
I would like to see the output from Test004 include all the same stack trace details that are included in Test003. (Since there is a slightly different chain of exceptions it will be slightly different output)
This stack overflow post explains the issue pretty well: https://stackoverflow.com/a/34433686/68042
Also, it looks like mstest from my console is doing something separately weird with how it displays aggregate exceptions. Any tips on where to open a ticket about that?
The text was updated successfully, but these errors were encountered: