Skip to content

Commit f76c43c

Browse files
committed
improved error reporting
1 parent a1fb916 commit f76c43c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/SpecBaseObject.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,16 @@ protected function instantiate($type, $data)
157157
return new Reference($data, $type);
158158
}
159159

160+
if (!is_array($data)) {
161+
throw new TypeErrorException(
162+
"Unable to instantiate {$type} Object with data '" . print_r($data, true) . "' at " . $this->getDocumentPosition()
163+
);
164+
}
160165
try {
161166
return new $type($data);
162167
} catch (\TypeError $e) {
163168
throw new TypeErrorException(
164-
"Unable to instantiate {$type} Object with data '" . print_r($data, true) . "'",
169+
"Unable to instantiate {$type} Object with data '" . print_r($data, true) . "' at " . $this->getDocumentPosition(),
165170
$e->getCode(),
166171
$e
167172
);

0 commit comments

Comments
 (0)