Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($injector): report circularity in circular dependency error message
Browse files Browse the repository at this point in the history
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.

Closes #7500
  • Loading branch information
teropa authored and rodyhaddad committed Jun 13, 2014
1 parent 3de07aa commit 545d22b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/auto/injectorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});


Expand All @@ -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');
});

});
Expand Down

0 comments on commit 545d22b

Please sign in to comment.