简体   繁体   中英

Dart2js error line numbers not accepted by source-map

I am trying to get useful errors out of dart2js generated javascript.

By placing this code in my index.html:

window.addEventListener(
    'error',
    function(e){
        ga(
            'send',
            'event',
            'JS Error',
            'msg:'+e.message,
            'line:'+e.lineno+' col:'+ e.colno+' file:'+e.filename,
            {'nonInteraction':1}
        );
    },false);

I get google analytics to give me line-numbers and column-numbers of errors that occur for users of my website.

Then I am using Mozilla's source-map consumer to find out where the original error occurred, like this (using github/mozilla/source-map/):

// some code removed for readability
require(["source-map/source-map-consumer"], function(SMC) {

var input = {
    line: parseInt(line),
    column: parseInt(col)
};

// rawSourceMap contains the dart2js generated source-map
var smc = new SMC.SourceMapConsumer(rawSourceMap);

console.log(smc.originalPositionFor(input));

The problem is that all I ever get is:

{
"source": null,
"line": null,
"column": null,
"name": null
}

While I am expecting something like

{
"source": "image.dart",
"line": 324,
"column": 2,
"name": "clickController"
}

What I found out so far is that the line numbers of errors are something like this line: 6862, column: 31 (a high line number a and a low column number).

After some testing and using smc.eachMapping() , I found out that linenumbers that give a result are like line: 7140, column: 1692 (high line number and high column number).

My question:
Does anybody have an idea why the dart2js javascript file generates errors that the dart2js source-map file cannot understand? (and how to fix this)

Kind regards and thanks for any help,
Hendrik Jan


Some extra info:

The pubspec.yaml looks like this:

name: bones
description: A sample web application
dependencies:
  browser: any
  observe: any
transformers:
  - $dart2js: {"minify":true, "checked":false}

I've already tried "minify":false and "checked":true to no avail.

An error looks like this:

Uncaught Uncaught Error: Invalid argument(s) Stack Trace: Invalid argument(s) at dart.b (.../script.dart.js?0:1245:3) at F.dart.F.T (.../script.dart.js?0:479:48) at J.aF ... and so on ...

I'm only guessing (since I don't see the stacktrace), but the top frame is probably a helper function. For example, instead of throwing an illegal argument exception inside the body dart2js might create a helper function "iae", and call that one instead.

This leads to smaller code, but the top-frame is then a function that doesn't exist in the source file. The iae function would also be shared by all callers and wouldn't help in debugging. Your approach of walking down the frames should yield the correct location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM