dart-lang / sdk

The Dart SDK, including the VM, dart2js, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
9.97k stars 1.53k forks source link

[dart2js] Error messages no longer appearing when running apps in Chrome #55891

Open nshahan opened 1 month ago

nshahan commented 1 month ago

Chrome recently made a change that broke the printing of our error messages in the console when errors are uncaught. See: https://chromium-review.googlesource.com/c/v8/v8/+/5378709

In this code I would hope to see the the cast failure message in the console:

@pragma('dart2js:noInline')
confuse(x) => x;

main() {
  confuse('hello') as int;
}

Instead all you get is:

Uncaught 
    at Object.wrapException (file:///Users/nshahan/code/test_files/dart2js/out.js:384:43)
    at Object._asInt (file:///Users/nshahan/code/test_files/dart2js/out.js:1110:15)
    at main (file:///Users/nshahan/code/test_files/dart2js/out.js:2320:9)
    at file:///Users/nshahan/code/test_files/dart2js/out.js:2681:7
    at file:///Users/nshahan/code/test_files/dart2js/out.js:2662:7
    at dartProgram (file:///Users/nshahan/code/test_files/dart2js/out.js:2675:5)
    at file:///Users/nshahan/code/test_files/dart2js/out.js:2684:3

If you inspect the error before it gets thrown you can still see .message contains "TypeError: "hello": type 'String' is not a subtype of type 'int'".

To fix this, it seems like we need to pass the message to the Error constructor. Then it appears in the console like it used to.

If you run the same code in firefox the console shows:

Uncaught : TypeError: "hello": type 'String' is not a subtype of type 'int'
    wrapException file:///Users/nshahan/code/test_files/dart2js/out.js:384
    _asInt file:///Users/nshahan/code/test_files/dart2js/out.js:1110
    main file:///Users/nshahan/code/test_files/dart2js/out.js:2320
    <anonymous> file:///Users/nshahan/code/test_files/dart2js/out.js:2681
    <anonymous> file:///Users/nshahan/code/test_files/dart2js/out.js:2662
    dartProgram file:///Users/nshahan/code/test_files/dart2js/out.js:2675
    <anonymous> file:///Users/nshahan/code/test_files/dart2js/out.js:2684

cc @rakudrama

userAdityaa commented 1 month ago

Hey, how to reproduce this code in chrome. I don't have any idea. Can you please help ?

nshahan commented 1 month ago

You must be running the current stable Chrome release to see the issue. There is a reproduction in this Chrome bug https://g-issues.chromium.org/issues/344629939.

ditman commented 1 week ago

b/350613557 exhibits this (cross-linking)

NVM, a fix seems to be coming to Canary (128)