brefphp / bref

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

Log error location #1635

Closed theoboldalex closed 6 months ago

theoboldalex commented 1 year ago

resolves #1619

So that we can see the context of an error in Cloudwatch logs, I have added an errorLocation key to the errorFormatted data structure. This means that the file and line number where the exception is thrown is logged.

theoboldalex commented 10 months ago

Any feedback on this appreciated @mnapoli

mnapoli commented 10 months ago

I'm sorry, while reviewing this I'm realizing this object follows a structure defined by AWS Lambda: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-invokeerror

Screen-001433

I apologize for not spotting that sooner 🤦

I'm thinking of 3 options:

  1. adding the extra errorLocation (current state of the PR) if it doesn't break error reporting and that new field shows up in the CloudWatch logs
  2. adding the file + line in the stack trace (insert it as the first line?
  3. adding the file + line to the error message

For reference, here's what PHP logs in case of an uncaught exception:

Screen-001434

Note: I don't think it's a good reference though because it's an "Uncaught exception" line that is a fatal error. In our case it's not exactly that, exceptions are OK (to communicate errors to Lambda), so we don't necessarily want to copy that format.

I think the 1st option is the best, but that requires testing on Lambda to confirm the behavior works as expected.

mnapoli commented 6 months ago

Closing inactive PRs, feel free to reopen.