Description
Please add your +1 👍 to let us know you have encountered this
Status:
Overview:
Adding a null value property to jsonPath function under StepFunctionsStartExecution
cause error while cdk synth.
TypeError: Cannot convert undefined or null to object
With the support of Jsonata we added additional check for Jsonata variables with function findJsonataExpressions which doesn't handle null values currently causing this issue:
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-stepfunctions/lib/fields.ts#L525
Affected version >= [email protected]
Complete Error Message:
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findJsonataExpressions=exports.isValidJsonataExpression=void 0;const isValidJsonataExpression=expression=>/^{%(.*)%}$/.test(expression);exports.isValidJsonataExpression=isValidJsonataExpression;const findJsonataExpressions=value=>{const recursive=v=>typeof v=="string"&&(0,exports.isValidJsonataExpression)(v)?[v]:Array.isArray(v)?v.flatMap(recursive):typeof v=="object"?Object.values(v).flatMap(recursive):[];return new Set(recursive(value))};exports.findJsonataExpressions=findJsonataExpressions;
^
TypeError: Cannot convert undefined or null to object
at Function.values (<anonymous>)
at recursive (/Users/shikagg/issue_34293/node_modules/aws-cdk-lib/aws-stepfunctions/lib/private/jsonata.js:1:455)
Workaround:
Solution:
Handle the null object in case no jsonata is provided,
PR : https://github.com/aws/aws-cdk/pull/34295/files
Related Issues:
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Version
2.177.0
Expected Behavior
Null values should be accepted
Current Behavior
Synthesis crashes with:
TypeError: Cannot convert undefined or null to object
Reproduction Steps
Create typescript cdk project with the test code:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
export class CdkBugStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const definition = new sfn.Pass(this, "Test step")
const stateMachine = new sfn.StateMachine(this, 'Steps', {
definitionBody: sfn.DefinitionBody.fromChainable(definition),
});
const task = new tasks.StepFunctionsStartExecution(this, 'Start migration process', {
stateMachine: stateMachine,
integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
input: sfn.TaskInput.fromObject({
token: sfn.JsonPath.taskToken,
nullProperty: null,
}),
});
}
}