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

aws-stepfunctions-tasks: addCatch does not support resultPath: DISCARD #26760

Closed
kopertop opened this issue Aug 15, 2023 · 3 comments · Fixed by #26770
Closed

aws-stepfunctions-tasks: addCatch does not support resultPath: DISCARD #26760

kopertop opened this issue Aug 15, 2023 · 3 comments · Fixed by #26770
Labels
@aws-cdk/aws-stepfunctions-tasks bug This issue is a bug. documentation This is a problem with documentation. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@kopertop
Copy link

Describe the bug

The LambdaInvoke package allows for an addCatch which is documented as allowing a CatchProps to include a resultPath special value of DISCARD

    /**
     * JSONPath expression to indicate where to inject the error data
     *
     * May also be the special value DISCARD, which will cause the error
     * data to be discarded.
     *
     * @default $
     */
    readonly resultPath?: string;

HOWEVER, when trying to add a catch with this special value of DISCARD for the resultPath it tosses an error:

Error: Expected JSON path to start with '$', got: DISCARD

Trace: Error: Expected JSON path to start with '$', got: DISCARD
    at renderJsonPath (node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/state.js:1:8225)
    at renderCatch (node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/state.js:1:7612)

Expected Behavior

The step function definition should use the special null value as the resultPath when passed the special DISCARD value.

Current Behavior

Attempted deploy causes the CDK to fail during validation:

Error: Expected JSON path to start with '$', got: DISCARD

Trace: Error: Expected JSON path to start with '$', got: DISCARD
    at renderJsonPath (node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/state.js:1:8225)
    at renderCatch (node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/state.js:1:7612)

Reproduction Steps

import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';

import { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';
import { DISCARD, StateMachine } from 'aws-cdk-lib/aws-stepfunctions';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';

export class SampleAppStack extends Stack {
	constructor(scope: Construct, id: string, props?: StackProps) {
		super(scope, id, props);
		const taskA = new LambdaInvoke(this, 'taskA', {
			resultPath: '$.Payload',
			lambdaFunction: new Function(this, 'taskAFnc', {
				runtime: Runtime.NODEJS_18_X,
				code: Code.fromInline('exports.handler = async () => { throw new Error("Error"); };'),
				handler: 'index.handler',
			}),
		});
		const taskB = new LambdaInvoke(this, 'taskB', {
			resultPath: '$.Payload',
			lambdaFunction: new Function(this, 'taskBFnc', {
				runtime: Runtime.NODEJS_18_X,
				code: Code.fromInline('exports.handler = async () => "OK";'),
				handler: 'index.handler',
			}),
		});
		taskA.addCatch(taskB, {
			resultPath: DISCARD,
		});

		const stateMachine = new StateMachine(this, 'SimpleStateMachine', {
			definition: taskA,
		});
	}
}

then run cdk synth

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.91.0 (build eea12ea)

Framework Version

No response

Node.js Version

v18.17.0

OS

Darwin razorcrest.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:23 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6020 arm64

Language

Typescript

Language Version

TypeScript (5.1.6)

Other information

No response

@kopertop kopertop added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 15, 2023
@kopertop
Copy link
Author

It looks like the correct code to use is JsonPath.DISCARD rather than just DISCARD. Solution may be to remove the extraneous DISCARD value that's also included, and update the documentation in the addCatch function to indicate using JsonPath.DISCARD

@peterwoodworth
Copy link
Contributor

Thanks for reporting the issue

I couldn't find anywhere that we use this variable

export const DISCARD = 'DISCARD';

I'm not sure if this constant has any legitimate use cases - I can't find anywhere it's being used within our codebase, and we only document JsonPath.DISCARD in the readmes and snippets. If it doesn't have any legitimate use cases, we should deprecate it, and perhaps make it more clear in the CatchProps snippet that we want JsonPath.DISCARD

@peterwoodworth peterwoodworth added good first issue Related to contributions. See CONTRIBUTING.md p2 effort/small Small work item – less than a day of effort documentation This is a problem with documentation. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 15, 2023
@mergify mergify bot closed this as completed in #26770 Aug 17, 2023
mergify bot pushed a commit that referenced this issue Aug 17, 2023
…e JsonPath.DISCARD in docs (#26770)

The `DISCARD` variable is removed because it unused. The docs are updated to be more clear to use `JsonPath.DISCARD` for `CatchProps` and `ChoiceProps`.

Closes #26760 .

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

rycerrat added a commit to aws-samples/aws-secure-environment-accelerator that referenced this issue Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions-tasks bug This issue is a bug. documentation This is a problem with documentation. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants