xp-forge / lambda

AWS Lambda for the XP Framework
3 stars 0 forks source link

Include exception cause in error output #16

Closed thekid closed 2 years ago

thekid commented 2 years ago

Before:

$ xp lambda test Env | tail -1 | json_pp
{
   "errorMessage" : "Test",
   "errorType" : "lang.IllegalArgumentException",
   "stackTrace" : [
      "Env::{closure}(...) (line 132 of AwsRunner.class.php)",
      "xp.lambda.AwsRunner::main(...) (line 389 of class-main.php)",
      "Env::{closure}(...) (line 132 of AwsRunner.class.php)",
      "xp.lambda.AwsRunner::main(...) (line 389 of class-main.php)"
   ]
}

After:

$ xp lambda test Env | tail -1 | json_pp
{
   "errorMessage" : "Test",
   "errorType" : "lang.IllegalArgumentException",
   "stackTrace" : [
      "Exception lang.IllegalArgumentException (Test)",
      "Env::{closure}(...) (line 112 of AwsRunner.class.php)",
      "xp.lambda.AwsRunner::main(...) (line 389 of class-main.php)",
      "Exception lang.IllegalStateException (Cause)",
      "Env::{closure}(...) (line 112 of AwsRunner.class.php)",
      "xp.lambda.AwsRunner::main(...) (line 389 of class-main.php)"
   ]
}
thekid commented 2 years ago

Here's a real life scenario where this is helpful:

image

Without the cause message, we would only be seeing the stack trace, and it wouldn't be as obvious why the request has failed. In this case, this is because the "zlib" extension isn't loaded (see https://github.com/xp-forge/lambda/issues/8)

thekid commented 2 years ago

Released in https://github.com/xp-forge/lambda/releases/tag/v4.2.0