How to get a de-obfuscated stack trace for a flutter web application
Asked Answered
P

1

6

I have a flutter web application (created with flutter build web) and when I run it, I get the following stack trace. Is there a way to convert this stacktrace to the original lines in the dart files? I noticed there is a main.dart.js.map but I'm not sure this is helpful here.

I run my application with

    runZonedGuarded(() async {
      WidgetsFlutterBinding.ensureInitialized();
      FlutterError.onError = (FlutterErrorDetails errorDetails) {
        debugPrint("Flutter error 1 ${errorDetails.exception.toString()}/${errorDetails.stack}");
      };

      runApp(MyApp());
    }, (error, stackTrace) {
      debugPrint("Flutter error 2 ${error.toString()}/$stackTrace");
    });

and I see the following exception.

Flutter error 2 Null check operator used on a null value/TypeError: Cannot read properties of null (reading 'fb')
main.dart.js:45362     at aqp.J (https://.../main.dart.js:122481:8)
main.dart.js:45362     at bk2.$1 (https://.../main.dart.js:75144:3)
main.dart.js:45362     at Object.bpJ (https://.../main.dart.js:7334:19)
...
Peary answered 17/11, 2021 at 14:8 Comment(2)
The mechanism you are looking for is called "source mapping". In short, along with the compiled/minimized/obfuscated code you provide the original source code as well as a mapping file ins a specific format, which is then read by whatever creates the stack trace to substitute references to the compiled files with references to the source files. As I am not a Flutter/Dart specialist, that's about all I can say.August
There is a main.dart.js.map present on the server and I've checked, in the browser, the option "Enable JavaScript source maps". And the last line of my main.dart.js is "//# sourceMappingURL=main.dart.js.map " I'm probably missing something trivialPeary
S
1

First, have you build your application with the --source-maps flag?

Second, the error "Null check operator used on a null value" is relative to the fact you have indicate in your source code that en variable is never null with the ! operator.

So, inspect ! operators used in your app, one of them is used on a null variable.

In general don't use these this operator without a null chec test before.

Someting like this:

if (myitem != null) {
    var a = myitem!.foo;
}
Stoddard answered 4/3 at 11:19 Comment(1)
I did compile with --source-maps. The question is not specific for this particular error though. I understand the error but would like to understand where it comes from by looking at a, readable, stack trace.Peary

© 2022 - 2024 — McMap. All rights reserved.