basic async-interop support; generator consumer missing
[m6w6/seekat] / lib / Exception / functions.php
diff --git a/lib/Exception/functions.php b/lib/Exception/functions.php
new file mode 100644 (file)
index 0000000..08c8ddb
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+namespace seekat\Exception;
+
+/**
+ * Canonical error message from a string or Exception
+ * @param string|Exception $error
+ * @return string
+ */
+function message(&$error) : string {
+       if ($error instanceof \Throwable) {
+               $message = $error->getMessage();
+       } else {
+               $message = $error;
+               $error = new \Exception($error);
+       }
+       return $message;
+}