From e455fd76eb5dab81dfb1b5c7111a6d79fed32eb4 Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Wed, 9 Dec 2020 07:44:47 +0700 Subject: [PATCH] improve repl error messages --- run.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/run.php b/run.php index cf8ce4d..4c3370f 100644 --- a/run.php +++ b/run.php @@ -21,7 +21,19 @@ function ml_repl($lisp) } catch (MadLisp\MadLispException $ex) { print('error: ' . $ex->getMessage()); } catch (TypeError $ex) { - print('error: invalid argument type: ' . $ex->getMessage()); + // Clean up the error message a little + if (preg_match('/must be an instance of ([^,]+), (.+) given/', $ex->getMessage(), $matches)) { + $message = 'expected ' . $matches[1] . ', ' . $matches[2] . ' given'; + } elseif (preg_match('/must be of the type ([^,]+), (.+) given/', $ex->getMessage(), $matches)) { + $message = 'expected ' . $matches[1] . ', ' . $matches[2] . ' given'; + } else { + $message = $ex->getMessage(); + } + + print('error: invalid argument type: ' . $message); + } catch (Throwable $ex) { + // Catch all other exceptions + print('error: ' . $ex->getMessage()); } print(PHP_EOL);