From af2436d7cc555216526052b901583c0e75dddb24 Mon Sep 17 00:00:00 2001
From: Bruce Wells <bruce.wells@simparel.com>
Date: Mon, 27 Aug 2018 17:47:28 -0400
Subject: Exception Messages

Basically the token that is causing the exception for better diagnostics.
---
 src/NXP/Classes/Calculator.php   | 2 +-
 src/NXP/Classes/TokenFactory.php | 6 +++---
 src/NXP/MathExecutor.php         | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/NXP/Classes/Calculator.php b/src/NXP/Classes/Calculator.php
index 41e0d9f..b584d69 100644
--- a/src/NXP/Classes/Calculator.php
+++ b/src/NXP/Classes/Calculator.php
@@ -40,7 +40,7 @@ class Calculator
             if ($token instanceof TokenVariable) {
                 $variable = $token->getValue();
                 if (!array_key_exists($variable, $variables)) {
-                    throw new UnknownVariableException();
+                    throw new UnknownVariableException($variable);
                 }
                 $value = $variables[$variable];
                 array_push($stack, new TokenNumber($value));
diff --git a/src/NXP/Classes/TokenFactory.php b/src/NXP/Classes/TokenFactory.php
index 19ba1cf..07b9ea8 100644
--- a/src/NXP/Classes/TokenFactory.php
+++ b/src/NXP/Classes/TokenFactory.php
@@ -61,7 +61,7 @@ class TokenFactory
         $class = new \ReflectionClass($operatorClass);
 
         if (!in_array('NXP\Classes\Token\InterfaceToken', $class->getInterfaceNames())) {
-            throw new UnknownOperatorException;
+            throw new UnknownOperatorException($operatorClass);
         }
 
         $this->operators[] = $operatorClass;
@@ -140,10 +140,10 @@ class TokenFactory
             if (isset($this->functions[$token])) {
                 return new TokenFunction($this->functions[$token]);
             } else {
-                throw new UnknownFunctionException();
+                throw new UnknownFunctionException($token);
             }
         }
 
-        throw new UnknownTokenException();
+        throw new UnknownTokenException($token);
     }
 }
diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php
index f348355..02b034f 100644
--- a/src/NXP/MathExecutor.php
+++ b/src/NXP/MathExecutor.php
@@ -92,7 +92,7 @@ class MathExecutor
     public function setVar($variable, $value)
     {
         if (!is_numeric($value)) {
-            throw new \Exception("Variable value must be a number");
+            throw new \Exception("Variable ({$variable}) value must be a number ({$value})");
         }
 
         $this->variables[$variable] = $value;
-- 
cgit v1.2.3


From 7db873a63655258bd30ff2d83f186da48f2c50e1 Mon Sep 17 00:00:00 2001
From: Bruce Wells <bruce.wells@simparel.com>
Date: Wed, 5 Sep 2018 18:17:05 -0400
Subject: Added variable type to diagnostic message

---
 src/NXP/MathExecutor.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php
index 02b034f..80f0bde 100644
--- a/src/NXP/MathExecutor.php
+++ b/src/NXP/MathExecutor.php
@@ -92,7 +92,7 @@ class MathExecutor
     public function setVar($variable, $value)
     {
         if (!is_numeric($value)) {
-            throw new \Exception("Variable ({$variable}) value must be a number ({$value})");
+            throw new \Exception("Variable ({$variable}) value must be a number ({$value}) type ({gettype($value)})");
         }
 
         $this->variables[$variable] = $value;
-- 
cgit v1.2.3