Skip to content

Commit

Permalink
Adjusts errorLocation to be an array not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
theoboldalex committed Sep 3, 2023
1 parent 6e2cf07 commit 26bb3a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Runtime/LambdaRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function signalFailure(string $invocationId, Throwable $error): void
$errorFormatted = [
'errorType' => get_class($error),
'errorMessage' => $error->getMessage(),
'errorLocation' => 'File: ' . $error->getFile() . ', Line: ' . $error->getLine(),
'errorLocation' => ['file' => $error->getFile(), 'line' => $error->getLine()],
'stack' => $stackTraceAsArray,
];

Expand All @@ -202,7 +202,7 @@ private function signalFailure(string $invocationId, Throwable $error): void
$previousErrors[] = [
'errorType' => get_class($previousError),
'errorMessage' => $previousError->getMessage(),
'errorLocation' => 'File: ' . $previousError->getFile() . ', Line: ' . $previousError->getLine(),
'errorLocation' => ['file' => $previousError->getFile(), 'line' => $previousError->getLine()],
'stack' => explode(PHP_EOL, $previousError->getTraceAsString()),
];
} while ($previousError->getPrevious() !== null);
Expand Down Expand Up @@ -231,7 +231,7 @@ private function signalFailure(string $invocationId, Throwable $error): void
$this->postJson($url, [
'errorType' => get_class($error),
'errorMessage' => $error->getMessage(),
'errorLocation' => 'File: ' . $error->getFile() . ', Line: ' . $error->getLine(),
'errorLocation' => ['file' => $error->getFile(), 'line' => $error->getLine()],
'stackTrace' => $stackTraceAsArray,
]);
}
Expand Down
18 changes: 12 additions & 6 deletions tests/Runtime/LambdaRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function test exceptions in the handler result in an invocation 
throw $exception;
});

$errorLocation = 'File: ' . $exception->getFile() . ', Line: ' . $exception->getLine();
$errorLocation = ['file' => $exception->getFile(), 'line' => $exception->getLine()];
$this->assertFalse($output);
$this->assertInvocationErrorResult(
'RuntimeException',
Expand All @@ -107,7 +107,7 @@ public function test nested exceptions in the handler result in an invo
throw $currentException;
});

$errorLocation = 'File: ' . $currentException->getFile() . ', Line: ' . $currentException->getLine();
$errorLocation = ['file' => $currentException->getFile(), 'line' => $currentException->getLine()];
$this->assertInvocationErrorResult(
'RuntimeException',
'This is an exception',
Expand All @@ -118,12 +118,18 @@ public function test nested exceptions in the handler result in an invo
[
'errorClass' => 'RuntimeException',
'errorMessage' => 'The previous exception.',
'errorLocation' => 'File: ' . $previousException->getFile() . ', Line: ' . $previousException->getLine()
'errorLocation' => [
'file' => $previousException->getFile(),
'line' => $previousException->getLine()
]
],
[
'errorClass' => 'Exception',
'errorMessage' => 'The original exception.',
'errorLocation' => 'File: ' . $originalException->getFile() . ', Line: ' . $originalException->getLine()
'errorLocation' => [
'file' => $originalException->getFile(),
'line' => $originalException->getLine()
]
],
]);
}
Expand Down Expand Up @@ -423,7 +429,7 @@ private function assertInvocationResult(mixed $result)
$this->assertEquals($result, json_decode($eventResponse->getBody()->__toString(), true, 512, JSON_THROW_ON_ERROR));
}

private function assertInvocationErrorResult(string $errorClass, string $errorMessage, string $errorLocation = '')
private function assertInvocationErrorResult(string $errorClass, string $errorMessage, array $errorLocation = [])
{
$requests = Server::received();
$this->assertCount(2, $requests);
Expand All @@ -450,7 +456,7 @@ private function assertInvocationErrorResult(string $errorClass, string $errorMe
$this->assertIsArray($invocationResult['stackTrace']);
}

private function assertErrorInLogs(string $errorClass, string $errorMessage, string $errorLocation = ''): void
private function assertErrorInLogs(string $errorClass, string $errorMessage, array $errorLocation = []): void
{
// Decode the logs from stdout
$stdout = $this->getActualOutput();
Expand Down

0 comments on commit 26bb3a5

Please sign in to comment.