Skip to content

Commit

Permalink
Fix for result builder
Browse files Browse the repository at this point in the history
  • Loading branch information
tuqqu committed Oct 7, 2023
1 parent c0258ba commit bcd236b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
27 changes: 13 additions & 14 deletions src/Interpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function __construct(
* Creates an interpreter instance
*
* @param string $source Source code to execute
* @param array $argv Command line arguments
* @param list<GoValue> $argv Command line arguments
* @param BuiltinProvider|null $builtin Builtin package provider
* @param ErrorHandler|null $errorHandler Error handler
* @param StreamProvider $streams Stream provider of stdout, stderr, stdin
Expand All @@ -172,7 +172,7 @@ public function __construct(
* @param bool $toplevel Whether the source is a top level code or not
* @param bool $debug Whether to enable debug mode or not
* @param Debugger|null $debugger Debugger, if $debug is set to false, this is ignored
* @param array $customFileExtensions Custom file extensions to include when importing
* @param list<string> $customFileExtensions Custom file extensions to include when importing
*
* @return self
*/
Expand Down Expand Up @@ -231,9 +231,7 @@ public static function create(
public function run(): RuntimeResult
{
$resultBuilder = new RuntimeResultBuilder();
if ($this->debugger !== null) {
$resultBuilder->setDebugger($this->debugger);
}
$resultBuilder->setDebugger($this->debugger);

try {
$ast = $this->parseSourceToAst($this->source);
Expand All @@ -244,19 +242,20 @@ public function run(): RuntimeResult
$this->callFunc($call);
} catch (RuntimeError|PanicError $error) {
$this->errorHandler->onError($error);
$resultBuilder->setExitCode(ExitCode::Failure);
$resultBuilder->setError($error);

return $resultBuilder->build();
return $resultBuilder
->setExitCode(ExitCode::Failure)
->setError($error)
->build();
} catch (AbortExecutionError) {
$resultBuilder->setExitCode(ExitCode::Failure);

return $resultBuilder->build();
return $resultBuilder
->setExitCode(ExitCode::Failure)
->build();
}

$resultBuilder->setExitCode(ExitCode::Success);

return $resultBuilder->build();
return $resultBuilder
->setExitCode(ExitCode::Success)
->build();
}

/**
Expand Down
16 changes: 12 additions & 4 deletions src/RuntimeResultBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,32 @@ final class RuntimeResultBuilder
private ?GoError $error = null;
private ?ExitCode $exitCode = null;

public function setExitCode(ExitCode $exitCode): void
public function setExitCode(ExitCode $exitCode): self
{
$this->exitCode = $exitCode;

return $this;
}

public function setResult(GoValue $result): void
public function setResult(?GoValue $result): self
{
$this->result = $result;

return $this;
}

public function setDebugger(Debugger $debugger): void
public function setDebugger(?Debugger $debugger): self
{
$this->debugger = $debugger;

return $this;
}

public function setError(GoError $error): void
public function setError(?GoError $error): self
{
$this->error = $error;

return $this;
}

public function build(): RuntimeResult
Expand Down

0 comments on commit bcd236b

Please sign in to comment.