bref icon indicating copy to clipboard operation
bref copied to clipboard

Include the file + line number in the Lambda failure logs

Open driskell opened this issue 1 year ago • 3 comments

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 avatar Aug 16 '23 16:08 driskell

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!

mnapoli avatar Aug 16 '23 17:08 mnapoli

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

theoboldalex avatar Sep 03 '23 18:09 theoboldalex

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.

driskell avatar Sep 03 '23 20:09 driskell