From 302ffe907f0175709661162a34369d70413d40cc Mon Sep 17 00:00:00 2001 From: Tero Parviainen Date: Sat, 17 May 2014 19:44:50 +0300 Subject: [PATCH] feat($injector): report circularity in circular dependency error message Change the error message for a circular dependency to display the full circle back to the first service being instantiated, so that the problem is obvious. The previous message stopped one dependency short of the full circle. Changes the content of the cdep error message, which may be considered a breaking change. --- src/auto/injector.js | 3 ++- test/auto/injectorSpec.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/auto/injector.js b/src/auto/injector.js index 5cfd4bb2430a..8017afd38750 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -749,7 +749,8 @@ function createInjector(modulesToLoad, strictDi) { function getService(serviceName) { if (cache.hasOwnProperty(serviceName)) { if (cache[serviceName] === INSTANTIATING) { - throw $injectorMinErr('cdep', 'Circular dependency found: {0}', path.join(' <- ')); + throw $injectorMinErr('cdep', 'Circular dependency found: {0}', + serviceName + ' <- ' + path.join(' <- ')); } return cache[serviceName]; } else { diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index 3b3fbeec1436..6b731fe796e4 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -656,7 +656,7 @@ describe('injector', function() { $provide.factory('service', function(service){}); return function(service) {}; }]); - }).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: service'); + }).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: service <- service'); }); @@ -667,7 +667,7 @@ describe('injector', function() { $provide.factory('b', function(a){}); return function(a) {}; }]); - }).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: b <- a'); + }).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: a <- b <- a'); }); });