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

Include the file + line number in the Lambda failure logs #1619

Open
driskell opened this issue Aug 16, 2023 · 3 comments
Open

Include the file + line number in the Lambda failure logs #1619

driskell opened this issue Aug 16, 2023 · 3 comments

Comments

@driskell
Copy link

driskell commented Aug 16, 2023

Description:

When a lambda invoke error occurs, you get an error like follows in CloudWatch:

7a3b55ac-f1df-417f-9414-230fda2acb1f	Invoke Error	
{
    "errorType": "ErrorException",
    "errorMessage": "Warning: Trying to access array offset on value of type null",
    "stack": [
        "#0 /var/task/custom_code(24): CustomCode->handle(Array)",
        "#1 /var/task/vendor/bref/bref/src/Runtime/Invoker.php(29): Bref\\Runtime\\FileHandlerLocator::{closure}(Array, Object(Bref\\Context\\Context))",
        "#2 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(89): Bref\\Runtime\\Invoker->invoke(Object(Closure), Array, Object(Bref\\Context\\Context))",
        "#3 /var/task/vendor/bref/bref/src/FunctionRuntime/Main.php(37): Bref\\Runtime\\LambdaRuntime->processNextEvent(Object(Closure))",
        "#4 /opt/bref/bootstrap.php(17): Bref\\FunctionRuntime\\Main::run()",
        "#5 {main}"
    ]
}

However, the stack is only showing the stack - not the current context of the error. In this case we called CustomCode->handle but there is no notification of the file that is in, nor the line number the error occurred on. Some errors raised by PHP contain this information where in the message it says (on line X in Y) but some errors do not (not entirely sure why to be honest!).

How to reproduce:

PHP 8.0
Access array offset on null and see if the line number appears

@driskell driskell added the bug label Aug 16, 2023
@mnapoli mnapoli added enhancement and removed bug labels Aug 16, 2023
@mnapoli
Copy link
Member

mnapoli commented Aug 16, 2023

Very good point, we can probably add that information here:

$errorFormatted = [
'errorType' => get_class($error),
'errorMessage' => $error->getMessage(),
'stack' => $stackTraceAsArray,
];

Feel free to open up a PR if you have time!

@mnapoli mnapoli changed the title Lambda invoke failure does not return file or line number Include the file + line number in the Lambda failure logs Aug 16, 2023
@theoboldalex
Copy link
Contributor

I can get a PR in for this enhancement if @driskell hasn't already got something in the works.

@driskell
Copy link
Author

driskell commented Sep 3, 2023

I can get a PR in for this enhancement if @driskell hasn't already got something in the works.

Nothing in the works currently. Thank you if you do have time to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants