Skip to content

Commit

Permalink
Fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnekaunisto committed Mar 5, 2021
1 parent 109419c commit f56c8c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ export class StateMachine extends StateMachineBase {

private validateStateMachineName(stateMachineName: string) {
if (stateMachineName.length < 1 || stateMachineName.length > 80) {
throw new Error('StateMachine name length must be between 1 and 80 characters');
throw new Error(`State Machine name must be between 1 and 80 characters. Received: ${stateMachineName}`);
}
if (stateMachineName.match('[0-9a-zA-Z\_\-]+')?.length != 1) {
throw new Error('StateMachine name must match [0-9a-zA-Z\_\-]+');
if (!stateMachineName.match('^[0-9a-zA-Z\_\-]+$')) {
throw new Error(`State Machine name must match "^[0-9a-zA-Z\_\-]+$". Received: ${stateMachineName}`);
}
}

Expand Down
10 changes: 6 additions & 4 deletions packages/@aws-cdk/aws-stepfunctions/test/state-machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ describe('State Machine', () => {
stateMachineType: stepfunctions.StateMachineType.EXPRESS,
});
};
const tooLongName = 'M'.repeat(81);
const invalidCharactersName = '*';

// THEN
expect(() => {
createStateMachine('M'.repeat(81));
}).toThrow('StateMachine name length must be between 1 and 80 characters');
createStateMachine(tooLongName);
}).toThrow(`State Machine name must be between 1 and 80 characters. Received: ${tooLongName}`);

expect(() => {
createStateMachine('*');
}).toThrow('StateMachine name must match [0-9a-zA-Z\_\-]+');
createStateMachine(invalidCharactersName);
}).toThrow(`State Machine name must match "^[0-9a-zA-Z\_\-]+$". Received: ${invalidCharactersName}`);
});

test('log configuration', () => {
Expand Down

0 comments on commit f56c8c7

Please sign in to comment.