Skip to content

Adding a ResultPath to a Catch doesn't work unless you add one outside the catch too #369

Closed
@LL782

Description

@LL782

What went wrong?
I had a state machine definition with a Catch on a Task. When I added a ResultPath to the Catcher I got an error when trying to deploy.

What did you expect should have happened?

I expected deployment to be successful and the catcher to use the ResultPath. Note, this is valid in the the JSON definition that appears in the AWS Console. There shoudn't be an error.

What was the config you used?

// ...

const serverlessConfiguration = {
  service: {
    name: "content-migration",
  },
  frameworkVersion: ">=1.72.0",
  custom: {
    webpack: {
      webpackConfig: "./webpack.config.js",
      includeModules: true,
    },
  },
  plugins: ["serverless-step-functions", "serverless-webpack"],
  provider: {
    name: "aws",
    region: "eu-west-1",
    runtime: "nodejs12.x",
    timeout: 60,
    environment: {
      AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1",
    },
  },
  functions: {
    createImageInContentful: {
      handler: "src/titles/createImage.handler",
      description: "Create an image asset in Contentful",
      environment: { ...contentfulEnvironmentVariables },
    },
    publishImageInContentful: {
      handler: "src/titles/publishImage.handler",
      description: "Publish an image asset in Contentful",
      environment: { ...contentfulEnvironmentVariables },
    },
  },
  stepFunctions: {
    stateMachines: {
      migrateAllTitlesMainImage: {
        name: "MigrateAllTitlesMainImage",
        definition: {
          Comment: "Migrate images from titles from Airtable into Contentful",
          StartAt: "MigrateAll",
          States: {
            MigrateAll: {
              Type: "Map",
              End: true,
              ItemsPath: "$.titles",
              Iterator: {
                StartAt: "CreateContentfulAsset",
                States: {
                  CreateContentfulAsset: {
                    Type: "Task",
                    Next: "PublishContentfulAsset",
                    Resource: {
                      "Fn::GetAtt": ["createImageInContentful", "Arn"],
                    },
                    Catch: [
                      {
                        ErrorEquals: ["VersionMismatch"],
                        ResultPath: "$.CreateContentfulAssetError",
                        Next: "AssetAlreadyCreated",
                      },
                    ],
                  },
                  AssetAlreadyCreated: {
                    Type: "Pass",
                    Next: "PublishContentfulAsset",
                  },
                  PublishContentfulAsset: {
                    Type: "Task",
                    End: true,
                    Resource: {
                      "Fn::GetAtt": ["publishImageInContentful", "Arn"],
                    },
                  },
                },
              },
            },
          },
        },
      },
    },
    activities: ["content-migration-titles-images"],
    validate: true,
  },
};

module.exports = serverlessConfiguration;

What stacktrace or error message from your provider did you see?

I got this in the console after running serverless deploy

Serverless Error ---------------------------------------

✕ State machine "migrateAllTitlesMainImage" definition is invalid:
undefined: undefined
No errors

Additional Data

  • Serverless Framework Core Version you're using: 1.78.1
  • The Plugin Version you're using: 2.22.1
  • Operating System: MacOS
  • Stack Trace: n/a
  • Provider Error messages: see above

Note

I notice in your example there is a ResultPath for the state itself. Adding this to my task makes the issue go away

CreateContentfulAsset: {
  Type: "Task",
  Next: "PublishContentfulAsset",
  Resource: {
    "Fn::GetAtt": ["createImageInContentful", "Arn"],
  },
  Catch: [
    {
      ErrorEquals: ["VersionMismatch"],
      ResultPath: "$.CreateContentfulAssetError",
      Next: "AssetAlreadyCreated",
    },
  ],
+  ResultPath: "$.CreateContentfulAssetResult",
},

I think that either this should be fixed (to stay in sync with what works in AWS) or a more informative error should be output to save time for anyone who hits this error.

BTW thanks for a great plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions