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

Commit 14e797c

Browse files
teroparodyhaddad
authored andcommitted
fix($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. Closes #7500
1 parent 82cd6b8 commit 14e797c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/auto/injector.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,8 @@ function createInjector(modulesToLoad) {
724724
function getService(serviceName) {
725725
if (cache.hasOwnProperty(serviceName)) {
726726
if (cache[serviceName] === INSTANTIATING) {
727-
throw $injectorMinErr('cdep', 'Circular dependency found: {0}', path.join(' <- '));
727+
throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
728+
serviceName + ' <- ' + path.join(' <- '));
728729
}
729730
return cache[serviceName];
730731
} else {

test/auto/injectorSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ describe('injector', function() {
630630
$provide.factory('service', function(service){});
631631
return function(service) {};
632632
}]);
633-
}).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: service');
633+
}).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: service <- service');
634634
});
635635

636636

@@ -641,7 +641,7 @@ describe('injector', function() {
641641
$provide.factory('b', function(a){});
642642
return function(a) {};
643643
}]);
644-
}).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: b <- a');
644+
}).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: a <- b <- a');
645645
});
646646

647647
});

0 commit comments

Comments
 (0)