Skip to content

fix: fix some of the papercuts and bugs i encoutered in the akaunting demo #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading