Fix issue with stack traces getting mangled#59900
Conversation
This comment has been minimized.
This comment has been minimized.
|
(original commit was missing the newly added test file) |
|
Instead of dealing with the mangled stack traces in onError, I think it would be more beneficial to avoid non-vm stack traces being propagated in the first place because this may still crop up in other places. In my minimal repo, the problematic trace comes from the What we could do is define an errorCallback in our own flutter_test zone which demangles it, and then just replace the FlutterErrorDetails copy in onError with an assertion. Alternatively, we could modify |
|
I think the probem with setting up another zone for this is that the test, as written, is directly calling FlutterError.reportError with a mangled stack trace. It's not going through the zone error handling mechanism - it's created and caught in the test itself. This is a constructed case, but it matches what I've seen in some nested network exceptions elsewhere. It's not clear to me where or why the package:stack_trace types are getting introduced. Perhaps from package:test? I also wouldn't bank on getting package:stack_trace changed here - part of the point of that package is to make traces look more human friendly, as defined by that package. |
|
This is my first review, so please tell me if I'm doing anything wrong 😰 Yes, package:test is the one applying the zone to flutter tests: https://github.com/dart-lang/test/blob/658e47e99c170605f7ab7502c556aae295ed9f46/pkgs/test_api/lib/src/backend/invoker.dart#L386 I think the approach of demangling in onError will work to address any current bugs. The reason for my concerns about them being propagated to error handlers is that a few different places in flutter still make the assumption that a stack trace isn't mangled (and we could make it again in the future). After some digging it looks like the only uses of flutter/packages/flutter/test/foundation/assertions_test.dart Lines 23 to 33 in 4d7525f These will throw if a mangled stack is ever passed to them in the future. All three of us (!) originally thought this was coming from the vm, so at the very least |
|
I found a bunch of other places this could fail, basically any handler of
flutter/packages/flutter/test/rendering/rendering_tester.dart Lines 29 to 34 in 9de8bfe Tap tests: flutter/packages/flutter/test/gestures/tap_test.dart Lines 394 to 397 in 4d7525f A scaffold test: An object test: |
|
A lot of those other areas are more specialized and not exposed for use in end-users tests. I think we should fix them because it could be confusing for framework developers, but probably do so in another patch - unless you think there's a generalized solution for them. One thing I don't think we can do is have this check exist in the stack filter, since we don't want to add a dependency on package:stack_trace to the framework. |
|
Yeah, I couldn't come up with a good way for these to be filtered in the framework either (w/o the added dependency), maybe hix or goderbaur knows more. |
| /// The [exception] must not be null; other arguments can be left to | ||
| /// their default values. (`throw null` results in a | ||
| /// [NullThrownError] exception.) | ||
| // If you add a property to this class, do not forget to update [copyWith]. |
There was a problem hiding this comment.
should we say this on every class with a copyWith?
There was a problem hiding this comment.
That's fair, I had this in here before adding copy with. Removing.
|
We now call _unmangle in three places; does this make any of the preexisting ones redundant? |
goderbauer
left a comment
There was a problem hiding this comment.
LGTM modulo Hixie's comment about redundancy.
|
AFAICT, we could reduce the calls to _unmangle in Basically, we have to deal with the case where an uncaught exception (sync or async) is thrown in the test, and we have to deal with the case where |
|
To explain - we could reassing the |
|
I've no problem it being in three places so long as we're confident that none of those places are entirely redundant (i.e. are entirely subsumed by one of the others). Test frameworks are inherently pretty crazy because they have to deal with unpredictable failures almost by definition. |
|
Google testing passed! |
Description
Certain types of async errors can get through with a mangled stack trace today, which causes a failure noted in the linked bug - the stack frame parser does not want stack traces as they come from package:stack_trace, we want the raw ones.
Related Issues
Fixes #59893
Tests
I added the following tests:
Test that throws that kind of error and then that we don't run into issues trying to parse it. Also adds an assertion that we don't get an unmangled trace.
/cc @PixelToast
Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.