Skip to content

Commit f52f01a

Browse files
committed
merged branch fabpot/better-exception-messages (PR #6994)
This PR was merged into the 2.2 branch. Commits ------- 3053194 [DependencyInjection] enhanced some error messages Discussion ---------- [DependencyInjection] enhanced some error messages | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a
2 parents 30494b8 + 017921d commit f52f01a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Container.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ public function setParameter($name, $value)
192192
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
193193
{
194194
if (self::SCOPE_PROTOTYPE === $scope) {
195-
throw new InvalidArgumentException('You cannot set services of scope "prototype".');
195+
throw new InvalidArgumentException(sprintf('You cannot set service "%s" of scope "prototype".', $id));
196196
}
197197

198198
$id = strtolower($id);
199199

200200
if (self::SCOPE_CONTAINER !== $scope) {
201201
if (!isset($this->scopedServices[$scope])) {
202-
throw new RuntimeException('You cannot set services of inactive scopes.');
202+
throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
203203
}
204204

205205
$this->scopedServices[$scope][$id] = $service;

ContainerBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ private function createService(Definition $definition, $id)
857857
} elseif (null !== $definition->getFactoryService()) {
858858
$factory = $this->get($parameterBag->resolveValue($definition->getFactoryService()));
859859
} else {
860-
throw new RuntimeException('Cannot create service from factory method without a factory service or factory class.');
860+
throw new RuntimeException(sprintf('Cannot create service "%s" from factory method without a factory service or factory class.', $id));
861861
}
862862

863863
$service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments);
@@ -869,7 +869,7 @@ private function createService(Definition $definition, $id)
869869

870870
if (self::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) {
871871
if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
872-
throw new RuntimeException('You tried to create a service of an inactive scope.');
872+
throw new RuntimeException(sprintf('You tried to create the "%s" service of an inactive scope.', $id));
873873
}
874874

875875
$this->services[$lowerId = strtolower($id)] = $service;

0 commit comments

Comments
 (0)