Skip to content
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

Added option to configure number of backtraces in error message #131

Merged
merged 1 commit into from
May 15, 2024
Merged
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
12 changes: 7 additions & 5 deletions src/Results/SettledResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,21 @@ public function toResponse($request)
}

/**
* @param ?int $numberOfBacktraces
*
* Throw an exception if there was an error, otherwise do nothing.
*
* @throws Exception
*/
public function throw()
public function throw(?int $numberOfBacktraces)
{
if (!$this->isError()) {
return $this;
}

throw new LambdaExecutionException(sprintf('Lambda Execution Exception for %s: "%s".', ...[
get_class($this->function),
$this->errorAsString()
$this->errorAsString($numberOfBacktraces)
]));
}

Expand Down Expand Up @@ -187,16 +189,16 @@ public function trace()
return Arr::get($this->body(), 'trace', []);
}

public function errorAsString()
public function errorAsString(int $numberOfBacktraces = 2)
{
if (!$this->isError()) {
return '';
}

$message = Arr::get($this->body(), 'errorMessage', 'Unknown error.');

// Only the first two backtraces (plus the error) for the string.
$trace = array_slice($this->trace(), 0, 3);
// Only the number of backtraces (plus the error) for the string.
$trace = array_slice($this->trace(), 0, $numberOfBacktraces + 1);
$trace = implode(' ', array_map('trim', $trace));

if ($trace) {
Expand Down