brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.1k stars 367 forks source link

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

Open driskell opened 1 year ago

driskell commented 1 year ago

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

mnapoli commented 1 year ago

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

https://github.com/brefphp/bref/blob/e2488b4ffa6a7a1355ef88a6da0678c147c28363/src/Runtime/LambdaRuntime.php#L190-L194

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

theoboldalex commented 1 year ago

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

driskell commented 1 year ago

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.