diff --git a/src/ExtismValType.php b/src/ExtismValType.php index 0a78b0f..f3d5084 100644 --- a/src/ExtismValType.php +++ b/src/ExtismValType.php @@ -6,7 +6,7 @@ class ExtismValType { public const I32 = 0; public const I64 = 1; - public const PTR = I64; + public const PTR = ExtismValType::I64; public const F32 = 2; public const F64 = 3; public const V128 = 4; diff --git a/src/FunctionCallException.php b/src/FunctionCallException.php new file mode 100644 index 0000000..ff348a7 --- /dev/null +++ b/src/FunctionCallException.php @@ -0,0 +1,17 @@ +error = $error; + $this->functionName = $functionName; + } +} \ No newline at end of file diff --git a/src/Internal/LibExtism.php b/src/Internal/LibExtism.php index c145469..f0bda39 100644 --- a/src/Internal/LibExtism.php +++ b/src/Internal/LibExtism.php @@ -52,7 +52,7 @@ private function soname() case "Windows NT": return "extism.dll"; default: - throw new \Exception("Extism: unsupported platform " . $platform); + throw new \RuntimeException("Extism: unsupported platform " . $platform); } } diff --git a/src/Manifest/PathWasmSource.php b/src/Manifest/PathWasmSource.php index 72b243d..1306ab4 100644 --- a/src/Manifest/PathWasmSource.php +++ b/src/Manifest/PathWasmSource.php @@ -19,7 +19,7 @@ public function __construct($path, $name = null, $hash = null) $this->path = realpath($path); if (!$this->path) { - throw new \Exception("Path not found: '" . $path . "'"); + throw new \Extism\PluginLoadException("Path not found: '" . $path . "'"); } $this->name = $name ?? pathinfo($path, PATHINFO_FILENAME); diff --git a/src/Plugin.php b/src/Plugin.php index cb64314..4c88394 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -57,7 +57,7 @@ public function __construct(Manifest $manifest, bool $with_wasi = false, array $ if (\FFI::isNull($errPtr) == false) { $error = \FFI::string($errPtr); $this->lib->extism_plugin_new_error_free($errPtr); - throw new \Exception("Extism: unable to load plugin: " . $error); + throw new \Extism\PluginLoadException("Extism: unable to load plugin: " . $error); } $this->handle = $handle; @@ -93,13 +93,17 @@ public function functionExists(string $name) */ public function call(string $name, string $input = null): string { + if ($input == null) { + $input = ""; + } + $rc = $this->lib->extism_plugin_call($this->handle, $name, $input, strlen($input)); $msg = "code = " . $rc; $err = $this->lib->extism_error($this->handle); if ($err) { $msg = $msg . ", error = " . $err; - throw new \Exception("Extism: call to '" . $name . "' failed with " . $msg); + throw new \Extism\FunctionCallException("Extism: call to '" . $name . "' failed with " . $msg, $err, $name); } return $this->lib->extism_plugin_output_data($this->handle); diff --git a/src/PluginLoadException.php b/src/PluginLoadException.php new file mode 100644 index 0000000..e895a11 --- /dev/null +++ b/src/PluginLoadException.php @@ -0,0 +1,11 @@ +