Skip to content

Commit

Permalink
fix: fix some of the papercuts and bugs i encoutered in the akaunting…
Browse files Browse the repository at this point in the history
… demo (#28)

Fixes #27 
Fixes #26 
Fixes #25
  • Loading branch information
mhmd-azeez authored Oct 24, 2024
1 parent d50e8b5 commit 7a724da
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ExtismValType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/FunctionCallException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Extism;

class FunctionCallException extends \Exception
{
public string $error;
public string $functionName;

public function __construct(string $message, string $error, string $functionName)
{
parent::__construct($message);

$this->error = $error;
$this->functionName = $functionName;
}
}
2 changes: 1 addition & 1 deletion src/Internal/LibExtism.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Manifest/PathWasmSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/PluginLoadException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Extism;

class PluginLoadException extends \Exception
{
public function __construct(string $message)
{
parent::__construct($message);
}
}

0 comments on commit 7a724da

Please sign in to comment.