AngularJS 不再在 Firebug 控制台中显示特定错误
AngularJS doesn't show specific errors in the Firebug console anymore
我在我的应用程序中使用 AngularJS 和 angular-material 库。
问题是,每当控制器的任何功能发生任何错误时,它都不会显示具体错误,而是每次都显示相同的一般错误,通过查看无法确定问题出在哪里。
这是我的控制台中显示的错误。
TypeError: href is null stackFrame.js (line 357)
consoleLog/<() angular.js (line 12416)
$ExceptionHandlerProvider/this.$get</<() angular.js (line 9203)
processQueue() angular.js (line 14642)
scheduleProcessQueue/<() angular.js (line 14650)
$RootScopeProvider/this.$get</Scope.prototype.$eval() angular.js (line 15878)
$RootScopeProvider/this.$get</Scope.prototype.$digest() angular.js (line 15689)
$RootScopeProvider/this.$get</Scope.prototype.$apply() angular.js (line 15986)
done() angular.js (line 10511)
completeRequest() angular.js (line 10683)
requestLoaded() angular.js (line 10624)
这是该错误的屏幕截图。
PS:我正在使用 RequireJS JavaScript 库来延迟加载我的应用程序。我也在我的应用程序中使用 ui.router。
更新 1:
stackFrame.js 不是我的应用程序的 JavaScript 文件。 stackFrame.js的位置是:
chrome://firebug/content/debugger/stack/stackFrame.js
即使我在应用程序中遇到不同的错误,它也总是在我的任何控制器中的整个应用程序的同一行上显示相同的错误。
更新 2:
禁用 Firebug 有效。它显示了 Firefox 和 Chrome 控制台中的特定错误。
我想补充一点,当 $http.post()
的响应函数内部出现错误时,这种类型的错误显示在 Firebug 中。测试更多案例。
更新 3:
参考https://github.com/firebug/firebug/issues/7948,此问题已在firebug 2.0.13 中解决。
您可以在 AngularJs 中使用自定义异常处理。
app.config(function($provide){
$provide.decorator("$exceptionHandler", function($delegate, $injector){
return function(exception, cause){
var $rootScope = $injector.get("$rootScope");
$rootScope.addError({message:"Exception", reason:exception});
$delegate(exception, cause);
};
});
});
它会将所有错误发送到 $rootScope 以进行数据绑定,然后再允许调用落入默认实现(addError 是 $rootScope 上的自定义方法,而 $delegate 代表被修饰的服务)。
用于封装一些通用逻辑的错误服务。
app.factory("errors", function($rootScope){
return {
catch: function(message){
return function(reason){
$rootScope.addError({message: message, reason: reason})
};
}
};
});
处理错误:
TestService.doWork().then()
.catch(errors.catch("Could not complete work!"));
这显然是 Firebug 中的错误。其代码中的相关行是这一行:
如果你想解决这个问题,你应该file a bug report for Firebug。
我在我的应用程序中使用 AngularJS 和 angular-material 库。 问题是,每当控制器的任何功能发生任何错误时,它都不会显示具体错误,而是每次都显示相同的一般错误,通过查看无法确定问题出在哪里。
这是我的控制台中显示的错误。
TypeError: href is null stackFrame.js (line 357)
consoleLog/<() angular.js (line 12416)
$ExceptionHandlerProvider/this.$get</<() angular.js (line 9203)
processQueue() angular.js (line 14642)
scheduleProcessQueue/<() angular.js (line 14650)
$RootScopeProvider/this.$get</Scope.prototype.$eval() angular.js (line 15878)
$RootScopeProvider/this.$get</Scope.prototype.$digest() angular.js (line 15689)
$RootScopeProvider/this.$get</Scope.prototype.$apply() angular.js (line 15986)
done() angular.js (line 10511)
completeRequest() angular.js (line 10683)
requestLoaded() angular.js (line 10624)
这是该错误的屏幕截图。
PS:我正在使用 RequireJS JavaScript 库来延迟加载我的应用程序。我也在我的应用程序中使用 ui.router。
更新 1: stackFrame.js 不是我的应用程序的 JavaScript 文件。 stackFrame.js的位置是:
chrome://firebug/content/debugger/stack/stackFrame.js
即使我在应用程序中遇到不同的错误,它也总是在我的任何控制器中的整个应用程序的同一行上显示相同的错误。
更新 2:
禁用 Firebug 有效。它显示了 Firefox 和 Chrome 控制台中的特定错误。
我想补充一点,当 $http.post()
的响应函数内部出现错误时,这种类型的错误显示在 Firebug 中。测试更多案例。
更新 3:
参考https://github.com/firebug/firebug/issues/7948,此问题已在firebug 2.0.13 中解决。
您可以在 AngularJs 中使用自定义异常处理。
app.config(function($provide){
$provide.decorator("$exceptionHandler", function($delegate, $injector){
return function(exception, cause){
var $rootScope = $injector.get("$rootScope");
$rootScope.addError({message:"Exception", reason:exception});
$delegate(exception, cause);
};
});
});
它会将所有错误发送到 $rootScope 以进行数据绑定,然后再允许调用落入默认实现(addError 是 $rootScope 上的自定义方法,而 $delegate 代表被修饰的服务)。
用于封装一些通用逻辑的错误服务。
app.factory("errors", function($rootScope){
return {
catch: function(message){
return function(reason){
$rootScope.addError({message: message, reason: reason})
};
}
};
});
处理错误:
TestService.doWork().then()
.catch(errors.catch("Could not complete work!"));
这显然是 Firebug 中的错误。其代码中的相关行是这一行:
如果你想解决这个问题,你应该file a bug report for Firebug。