2016-12-05 58 views
2

我与AngularJS一个很奇怪的例外1.5.9

[$ rootScope:inprog]空正在进行

这里是该抛出异常的源代码:

function beginPhase(phase) { 
    if ($rootScope.$$phase) { 
    throw $rootScopeMinErr('inprog', '{0} already in progress', $rootScope.$$phase); 
    } 

    $rootScope.$$phase = phase; 
} 

beginPhase()被称为以“$应用”或“$文摘” 。

我的问题是:

  • 怎么可能进入 “如果”,而$ rootScope $$阶段为空?

任何帮助将不胜感激。

+0

为错误的文档,请访问https://docs.angularjs.org/error/$rootScope/inprog – georgeawg

+0

我得到通过我们的监控软件报告了类似的问题 - 出现这种情况,如果只有这样,你传递一个包含'null'作为函数参数的字符串。问题是beginPhase()在整个角度源中只调用两次 - 在两种情况下都需要'$ apply'或'$ digest'。所以,尽管这是一个线索,但我仍然难以确定导致这种情况发生的原因。 – Veetek

回答

1

要回答你的问题$ rootScope。$$阶段可以设置为“空”(串),这将导致引发此错误。

我不知道你是如何捕捉到这条消息的,但是Sentry报告说,对于我和我从一堆用户那里得到大量的异常。

所以为了减少the spam我做了一个函数,将异常删除堆栈,将清除$ rootScope $$阶段希望这将阻止第二次出现:

function exceptionHandler(){ 
    const error = Error; 
    const nullMessage = "[$rootScope:inprog] null already in progress"; 

    function exception(message){ 
     if(message.indexOf(nullMessage) === 0){ 
      const $rootScope = exceptionHandler.$rootScope; 
      if($rootScope) $rootScope.$$phase = null; 

      const exception = new error(nullMessage); 
      exception.stack = ""; 
      return exception; 
     } 

     return new error(message); 
    } 

    Error = exception; 
} 

exceptionHandler(); // If it's not run AngularJS will use the original Error constructor, the one we're decorating 

然后在angular.run注入$ rootScope并将其设置为功能的属性:

angular.run(["$rootScope", function($rootScope){ 
    exceptionHandler.$rootScope = $rootScope; 
}]); 

我的假设是,扩展设置为$ rootScope。$$阶段“null”但在安装与我的一个用户相同的扩展后,未发生异常。

Star on GistHub