AngularJS - Stack trace ignoring source map

后端 未结 6 1730
悲&欢浪女
悲&欢浪女 2020-12-13 18:46

I\'ve written an AngularJS app but it\'s proving a bit of a nightmare to debug. I\'m using Grunt + uglify to concatenate and minify my application code. It also creates a so

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 19:26

    Larrifax's answer is good but there is an improved version of the function documented in the same issue report:

    .config(function($provide) {
    
      // Fix sourcemaps
      // @url https://github.com/angular/angular.js/issues/5217#issuecomment-50993513
      $provide.decorator('$exceptionHandler', function($delegate) {
        return function(exception, cause) {
          $delegate(exception, cause);
          setTimeout(function() {
            throw exception;
          });
        };
      });
    })
    

    This will generate two stack traces, as Andrew Magee noted: one formatted by Angular, then a second one formatted by the browser. The second trace will apply sourcemaps. It's probably not a great idea to disable the duplicates, because you may have other Angular modules that also do work with exceptions that could be called after this via the delegation.

提交回复
热议问题