Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LL782 opened this issue Sep 9, 2020 · 3 comments

Comments

@LL782
Copy link

LL782 commented Sep 9, 2020

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.

@theburningmonk
Copy link
Collaborator

@LL782 turn turning off validate for now, it's relying on another project asl-validator which might be behind on the official spec.

I've used ResultPath with Catch before and it definitely works.

@LL782
Copy link
Author

LL782 commented Sep 18, 2020

@theburningmonk that's great info. thanks!

I'll perhaps take my issue to asl-validator

@theburningmonk
Copy link
Collaborator

@LL782 I've made a PR there already, once it gets merged I'll update the dependency here and it should be sorted then.

ss-betseqnzr pushed a commit to BetSEQNZR/serverless-step-functions that referenced this issue Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants