Skip to content

Commit 0f65ad1

Browse files
committed
Print value type on dump error
When your Definition contains invalid values, like an object or resource, an error is thrown. Often, it's hard to tell what causes it. By showing the type of the value, it can help developers resolve the problem faster.
1 parent 21869b2 commit 0f65ad1

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ private function dumpValue(mixed $value, bool $interpolate = true): string
19541954
} elseif ($value instanceof AbstractArgument) {
19551955
throw new RuntimeException($value->getTextWithContext());
19561956
} elseif (\is_object($value) || \is_resource($value)) {
1957-
throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
1957+
throw new RuntimeException(sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value)));
19581958
}
19591959

19601960
return $this->export($value);

Dumper/XmlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public static function phpToXml(mixed $value): string
414414
case $value instanceof \UnitEnum:
415415
return sprintf('%s::%s', $value::class, $value->name);
416416
case \is_object($value) || \is_resource($value):
417-
throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
417+
throw new RuntimeException(sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value)));
418418
default:
419419
return (string) $value;
420420
}

Dumper/YamlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private function dumpValue(mixed $value): mixed
307307
} elseif ($value instanceof AbstractArgument) {
308308
return new TaggedValue('abstract', $value->getText());
309309
} elseif (\is_object($value) || \is_resource($value)) {
310-
throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
310+
throw new RuntimeException(sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value)));
311311
}
312312

313313
return $value;

Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function testAddService()
203203
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
204204
} catch (\Exception $e) {
205205
$this->assertInstanceOf(RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
206-
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
206+
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource, got "stdClass".', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
207207
}
208208
}
209209

Tests/Dumper/XmlDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testAddService()
6363
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6464
} catch (\Exception $e) {
6565
$this->assertInstanceOf(\RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
66-
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
66+
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource, got "stdClass".', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6767
}
6868
}
6969

Tests/Dumper/YamlDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testAddService()
6565
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6666
} catch (\Exception $e) {
6767
$this->assertInstanceOf(\RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
68-
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
68+
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource, got "stdClass".', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6969
}
7070
}
7171

0 commit comments

Comments
 (0)