From faf81ef18a5a95859e433ed8b9f5d6f44319585a Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Mon, 3 Jul 2017 18:12:12 +0700 Subject: [PATCH] Catch exceptions in isValidPHPValue and return corresponding error message --- src/Executor/Values.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Executor/Values.php b/src/Executor/Values.php index ef33c5a..441dd04 100644 --- a/src/Executor/Values.php +++ b/src/Executor/Values.php @@ -243,16 +243,26 @@ class Values } if ($type instanceof LeafType) { - // Scalar/Enum input checks to ensure the type can parse the value to - // a non-null value. - $parseResult = $type->parseValue($value); - if (null === $parseResult) { - $v = json_encode($value); + try { + // Scalar/Enum input checks to ensure the type can parse the value to + // a non-null value. + $parseResult = $type->parseValue($value); + if (null === $parseResult) { + $v = json_encode($value); + return [ + "Expected type \"{$type->name}\", found $v." + ]; + } + return []; + } catch (\Exception $e) { return [ - "Expected type \"{$type->name}\", found $v." + $e->getMessage() + ]; + } catch (\Throwable $e) { + return [ + $e->getMessage() ]; } - return []; } throw new InvariantViolation('Must be input type');