11

The setup is an AWS Step Function with Lambdas which throw errors in a catch clause and should add them to the event payload for an Error Handler Lambda at the end of the chain. This is accomplished with adding a result path like

"Catch": [ {
  "ErrorEquals": [ "States.ALL" ],
  "ResultPath": "$.error-info",
  "Next": "Error Handler"
}]

as described in the docs: https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html.

I now need to create custom errors that include new fields lets say a new field called "lambdaName".

For that I would customize an error class like this:

class SFLambdaError extends Error {
    constructor(message,lambdaName){
        super(message)
        this.lambdaName = lambdaName
    }
}

Testing the Lambda directly this outputs the desired new field and looks fine:

Invoke Error    {"errorType":"SFLambdaError","errorMessage":"someNumber.replace is not a function","lambdaName":"testLambdaName","stack": (...)}

But when implemented in the flow of a Step Function and outputed into "error-info" of the event, the new fields got cut of like following:

"error-info": {
    "Error": "SFLambdaError",
    "Cause": "{\"errorType\":\"SFLambdaError\",\"errorMessage\":\"someNumber.replace is not a function\",\"trace\":[\"SFLambdaError: someNumber.replace is not a function\",\"    at Runtime.exports.handler (/var/task/index.js:27:23)\",\"    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)\"]}"

So it seems that SF error result path just allowes for the standard error class fields to be given out.

Work arounds I tested are to pass all desired fields in errorMessage via stringifying and parsing at the other end in the error handler. But I hope there must be a better way.

So my question: is there a thing I've overseen in the docs or a cleaner workaroun?

Thanks for any help!

1 Answer 1

3

Unfortunately there is no handy way to handle such case. A workaround is using an extra state with builtin intrinsic function States.StringToJson:


"Catch": [ {
  "ErrorEquals": [ "States.ALL" ],
  "ResultPath": "$.error-info",
  "Next": "Error Handler Preprocessing"
}]

...

"Error Handler Preprocessing": {
  "Type": "Pass",
  "Parameters": {
    "Error.$": "$.error-info.Error",
    "Cause.$": "States.StringToJson($.error-info.Cause)"
  },
  "ResultPath": "$.error-info",
  "Next": "Error Handler"
},

"Error Handler": {
  "Type": "Task",
  ...
}

References

Sign up to request clarification or add additional context in comments.

1 Comment

Wasn't the original question to get lambdaName to be sent to the error handler? This doesn't do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.