When an error is thrown, for example by the CloudFormation deployment, then it is caught and re-thrown as ServerlessError. That gives the following output:
Technically this was a bug, not sure how we can avoid wrapping that in ServerlessError, but anyway, that could have happened also with any CloudFormation error.
At this point I had no stack trace to debug. So that's where I added the first commit: log the stack trace to verbose for ServerlessError.
Here is the new output I got (in verbose):
It's a little bit more helpful, but actually the stack trace points me to where ServerlessError is thrown, which isn't helpful at all. I want the original error.
In PHP (inspired by Java) there's a very common pattern of rethrowing an exception while keeping the "previous" exception and its stack trace. I had a look at it seems doable in JS: https://stackoverflow.com/q/42754270/245552
So that's what the second commit is about: you can pass the "previous" exception (optionally), and you get it in the verbose output:
Now I was able to actually pinpoint the problem. The output is surely verbose and a bit more complex, but this is the verbose mode and at least I have all the info I need 🤷
Note that this PR doesn't contain an actual use case where I pass previous to ServerlessError because I used that in #124. We can make use of it later after everything is merged to main.
I made both of these changes while working on debugging this pattern in #124:
https://github.com/serverless/compose/blob/fa0306ad7ab1b9ab90d4e3cd007e4f8e2f8d684a/src/state/utils/get-compose-s3-state-bucket-name.js#L103-L114
When an error is thrown, for example by the CloudFormation deployment, then it is caught and re-thrown as
ServerlessError
. That gives the following output:Technically this was a bug, not sure how we can avoid wrapping that in
ServerlessError
, but anyway, that could have happened also with any CloudFormation error.At this point I had no stack trace to debug. So that's where I added the first commit: log the stack trace to verbose for
ServerlessError
.Here is the new output I got (in verbose):
It's a little bit more helpful, but actually the stack trace points me to where
ServerlessError
is thrown, which isn't helpful at all. I want the original error.In PHP (inspired by Java) there's a very common pattern of rethrowing an exception while keeping the "previous" exception and its stack trace. I had a look at it seems doable in JS: https://stackoverflow.com/q/42754270/245552
So that's what the second commit is about: you can pass the "previous" exception (optionally), and you get it in the verbose output:
Now I was able to actually pinpoint the problem. The output is surely verbose and a bit more complex, but this is the verbose mode and at least I have all the info I need 🤷
Note that this PR doesn't contain an actual use case where I pass
previous
toServerlessError
because I used that in #124. We can make use of it later after everything is merged tomain
.