dart-pad icon indicating copy to clipboard operation
dart-pad copied to clipboard

Exceptions in Console are broken

Open PiN73 opened this issue 4 years ago • 3 comments

What happened?

When rendering error occurs, console doesn't show correct exception and stacktrace

Steps to reproduce problem

Paste this code to DartPad and run it. Note: the code causes exception, this is on purpose.

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyWidget(),
    );
  }
}

class MyWidget extends LeafRenderObjectWidget {
  @override
  RenderObject createRenderObject(BuildContext context) {
    return RenderMyWidget();
  }
}

class RenderMyWidget extends RenderBox {}

Expected results

An exception with stacktrace should be printed to DartPad Console, like

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
RenderMyWidget did not implement performLayout().

RenderBox subclasses need to either override performLayout() to set a size and lay out any children, or, set sizedByParent to true so that performResize() sizes the render object.

The relevant error-causing widget was: ...
When the exception was thrown, this was the stack: ...

Actual results

In Firefox, the following is printed to DartPad Console:

Error: Assertion failed: file:///Users/brettmorgan/Documents/GitHub/dart-services/flutter-sdk/packages/flutter/lib/src/foundation/stack_frame.dart:114:12
match != null
"Expected DartError@https://storage.googleapis.com/nnbd_artifacts/2.12.3/dart_sdk.js:6666:7 to match RegExp/^(.+) (\\d+):(\\d+)\\s+(.+)$/."Error: Error: Assertion failed: file:///Users/brettmorgan/Documents/GitHub/dart-services/flutter-sdk/packages/flutter/lib/src/foundation/stack_frame.dart:114:12
match != null
"Expected DartError@https://storage.googleapis.com/nnbd_artifacts/2.12.3/dart_sdk.js:6666:7 to match RegExp/^(.+) (\\d+):(\\d+)\\s+(.+)$/."

In Chrome, DartPad Console simply says Script error., and exception is shown in Chrome DevTools Console:

dart_sdk.js:6666 Uncaught Error: Assertion failed: file:///Users/brettmorgan/Documents/GitHub/dart-services/flutter-sdk/packages/flutter/lib/src/foundation/stack_frame.dart:114:12
match != null
"Expected Error: Assertion failed: file:///Users/brettmorgan/Documents/GitHub/dart-services/flutter-sdk/packages/flutter/lib/src/foundation/stack_frame.dart:114:12 to match RegExp/^(.+) (\\d+):(\\d+)\\s+(.+)$/."
    at Object.throw_ [as throw] (dart_sdk.js:5031)
    at Object.assertFailed (dart_sdk.js:4970)
    at Function._parseWebDebugFrame (flutter_web.js:280054)
    at Function._parseWebFrame (flutter_web.js:280045)
    at MappedIterator.new.fromStackTraceLine (flutter_web.js:280086)
    at MappedIterator.new.moveNext (dart_sdk.js:21784)
    at WhereTypeIterator.new.moveNext (dart_sdk.js:22774)
    at JsIterator.next (dart_sdk.js:6699)
    at Function.of (dart_sdk.js:42950)
    at WhereTypeIterable.new.toList (dart_sdk.js:19942)
    at Function.fromStackString (flutter_web.js:280041)
    at Function.fromStackTrace (flutter_web.js:280037)
    at assertions.FlutterErrorDetails.new.debugFillProperties (flutter_web.js:276109)
    at flutter_web.js:276490
    at assertions._FlutterErrorDetailsNode.new.get builder (flutter_web.js:276493)
    at assertions._FlutterErrorDetailsNode.new.get builder [as builder] (flutter_web.js:276556)
    at assertions._FlutterErrorDetailsNode.new.getProperties (flutter_web.js:276505)
    at diagnostics$.TextTreeRenderer.new.[_debugRender] (flutter_web.js:278234)
    at diagnostics$.TextTreeRenderer.new.render (flutter_web.js:278148)
    at Function.dumpErrorToConsole (flutter_web.js:276223)
    at flutter_web.js:276356
    at Function.reportError (flutter_web.js:276317)
    at binding$.WidgetsFlutterBinding.new.[_invokeFrameCallback] (flutter_web.js:306739)
    at binding$.WidgetsFlutterBinding.new.handleDrawFrame (flutter_web.js:306706)
    at flutter_web.js:306620
    at internalCallback (dart_sdk.js:24050)

PiN73 avatar May 10 '21 12:05 PiN73

Moved from https://github.com/flutter/flutter/issues/82159

PiN73 avatar May 10 '21 12:05 PiN73

Or just

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ElevatedButton(
        onPressed: () => throw Exception(),
        child: const Text('Click'),
      ),
    );
  }
}

run, click

Firefox:

Error: Assertion failed: file:///Users/brettmorgan/Documents/GitHub/dart-services/flutter-sdk/packages/flutter/lib/src/foundation/stack_frame.dart:114:12
match != null
"Expected DartError@https://storage.googleapis.com/nnbd_artifacts/2.14.4/dart_sdk.js:6780:7 to match RegExp/^(.+) (\\d+):(\\d+)\\s+(.+)$/."Error: Error: Assertion failed: file:///Users/brettmorgan/Documents/GitHub/dart-services/flutter-sdk/packages/flutter/lib/src/foundation/stack_frame.dart:114:12
match != null
"Expected DartError@https://storage.googleapis.com/nnbd_artifacts/2.14.4/dart_sdk.js:6780:7 to match RegExp/^(.+) (\\d+):(\\d+)\\s+(.+)$/."

Chrome:

Script error.

PiN73 avatar Dec 23 '21 00:12 PiN73

The failures comes from the _parseWebDebugFrame method, which is trying to parse a stack frame containing the string DartError@[...], which it wasn't designed to expect.

The framework catches the exception and calls reportError, which calls dumpErrorToConsole, which calls debugPrintStack, which calls defaultStackFilter:

Log
Uncaught Error: Assertion failed: file:///Users/ryjohn/code/github/dart-lang/dart-services/flutter-sdks/stable/packages/flutter/lib/src/foundation/stack_frame.dart:114:12
match != null
"Expected Error: Assertion failed: file:///Users/ryjohn/code/github/dart-lang/dart-services/flutter-sdks/stable/packages/flutter/lib/src/foundation/stack_frame.dart:114:12 to match RegExp/^(.+) (\\d+):(\\d+)\\s+(.+)$/."
    at Object.throw_ [as throw] (errors.dart:251)
    at Object.assertFailed (errors.dart:29)
    at Function._parseWebDebugFrame (stack_frame.dart:114)
    at Function._parseWebFrame (stack_frame.dart:100)
    at MappedIterator.new.fromStackTraceLine (stack_frame.dart:202)
    at MappedIterator.new.moveNext (iterable.dart:391)
    at WhereTypeIterator.new.moveNext (iterable.dart:869)
    at JsIterator.next (operations.dart:748)
    at Function.of (core_patch.dart:527)
    at WhereTypeIterable.new.toList (iterable.dart:388)
    at Function.fromStackString (stack_frame.dart:89)
    at Function.fromStackTrace (stack_frame.dart:80)
    at binding$0.FlutterErrorDetailsForPointerEventDispatcher.new.debugFillProperties (assertions.dart:669)
    at diagnostics.dart:2950
    at assertions._FlutterErrorDetailsNode.new.get builder (diagnostics.dart:2952)
    at assertions._FlutterErrorDetailsNode.new.get builder [as builder] (assertions.dart:1245)
    at assertions._FlutterErrorDetailsNode.new.getProperties (diagnostics.dart:2967)
    at diagnostics$.TextTreeRenderer.new.[_debugRender] (diagnostics.dart:1244)
    at diagnostics$.TextTreeRenderer.new.render (diagnostics.dart:1121)
    at dumpErrorToConsole (assertions.dart:973)
    at Function.reportError (assertions.dart:1137)
    at binding$.WidgetsFlutterBinding.new.dispatchEvent (binding.dart:421)
    at binding$.WidgetsFlutterBinding.new.dispatchEvent (binding.dart:322)
    at binding$.WidgetsFlutterBinding.new.[_handlePointerEventImmediately] (binding.dart:374)
    at binding$.WidgetsFlutterBinding.new.handlePointerEvent (binding.dart:338)
    at binding$.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (binding.dart:296)
    at binding$.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (binding.dart:279)
    at Object.invoke1 (platform_dispatcher.dart:1020)
    at _engine.EnginePlatformDispatcher.__.invokeOnPointerDataPacket (platform_dispatcher.dart:184)
    at _engine.PointerBinding.__.[_onPointerData] (pointer_binding.dart:130)
    at pointer_binding.dart:558
    at pointer_binding.dart:511
    at loggedHandler (pointer_binding.dart:217)
DartError @ errors.dart:202
throw_ @ errors.dart:251
assertFailed @ errors.dart:29
_parseWebDebugFrame @ stack_frame.dart:114
_parseWebFrame @ stack_frame.dart:100
fromStackTraceLine @ stack_frame.dart:202
moveNext @ iterable.dart:391
moveNext @ iterable.dart:869
next @ operations.dart:748
of @ core_patch.dart:527
toList @ iterable.dart:388
fromStackString @ stack_frame.dart:89
fromStackTrace @ stack_frame.dart:80
debugFillProperties @ assertions.dart:669
(anonymous) @ diagnostics.dart:2950
get builder @ diagnostics.dart:2952
get builder @ assertions.dart:1245
getProperties @ diagnostics.dart:2967
[_debugRender] @ diagnostics.dart:1244
render @ diagnostics.dart:1121
dumpErrorToConsole @ assertions.dart:973
reportError @ assertions.dart:1137
dispatchEvent @ binding.dart:421
dispatchEvent @ binding.dart:322
[_handlePointerEventImmediately] @ binding.dart:374
handlePointerEvent @ binding.dart:338
[_flushPointerEventQueue] @ binding.dart:296
[_handlePointerDataPacket] @ binding.dart:279
invoke1 @ platform_dispatcher.dart:1020
invokeOnPointerDataPacket @ platform_dispatcher.dart:184
[_onPointerData] @ pointer_binding.dart:130
(anonymous) @ pointer_binding.dart:558
(anonymous) @ pointer_binding.dart:511
loggedHandler @ pointer_binding.dart:217
Show 4 more frames

It looks like we may need to adjust the defaultStackFilter RegExp in the SDK unless there's a way to modify the stack frame first.

johnpryan avatar Dec 23 '21 19:12 johnpryan

Duplicate of https://github.com/dart-lang/dart-pad/issues/1365

johnpryan avatar Oct 06 '22 00:10 johnpryan