Skip to content

Commit

Permalink
fix: support path fields on fail for cause and error
Browse files Browse the repository at this point in the history
  • Loading branch information
massfords authored and ChristopheBougere committed Nov 6, 2023
1 parent c33ac55 commit 7dc622e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/__tests__/definitions/invalid-fail-dupe-cause.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Comment": "Contains both Cause and CausePath when only one is allowed",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Fail",
"Cause": "CauseExample",
"CausePath": "$.cause",
"Error": "ErrorExample"
}
}
}
11 changes: 11 additions & 0 deletions src/__tests__/definitions/invalid-fail-dupe-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Comment": "Contains both Error and ErrorPath when only one is allowed",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Fail",
"Error": "CauseExample",
"ErrorPath": "$.error"
}
}
}
11 changes: 11 additions & 0 deletions src/__tests__/definitions/valid-fail-paths.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Comment": "Contrived example with a Fail state to show it satisfies the terminal state requirement",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Fail",
"CausePath": "$.path",
"ErrorPath": "States.Format('{}{}', $.field1, $field2)"
}
}
}
4 changes: 3 additions & 1 deletion src/__tests__/definitions/valid-fail.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Fail"
"Type": "Fail",
"Cause": "CauseExample",
"Error": "ErrorExample"
}
}
}
8 changes: 8 additions & 0 deletions src/schemas/fail.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
"Cause": {
"type": "string"
},
"CausePath": {
"$comment": "This field is a ReferencePath with limited Intrinsic Function support. Using string until custom validation is available.",
"type": "string"
},
"Error": {
"type": "string"
},
"ErrorPath": {
"$comment": "This field is a ReferencePath with limited Intrinsic Function support. Using string until custom validation is available.",
"type": "string"
}
},
"required": ["Type"],
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export enum StateMachineErrorCode {
MapToleratedFailureError = "MAP_TOLERATED_FAILURE",
MapMaxConcurrencyError = "MAP_CONCURRENCY_ERROR",
MapItemReaderMaxItemsError = "MAP_ITEMREADER_MAXITEM",
FailCauseProperty = "FAIL_CAUSE_PROPERTY",
FailErrorProperty = "FAIL_ERROR_PROPERTY",
}
export type StateMachineError = {
"Error code": StateMachineErrorCode;
Expand Down
14 changes: 14 additions & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ export = function validator(
errorCode: StateMachineErrorCode.MapItemBatcherError,
}),
},
{
filter: IsFail,
checker: AtMostOne({
props: ["Cause", "CausePath"],
errorCode: StateMachineErrorCode.FailCauseProperty,
}),
},
{
filter: IsFail,
checker: AtMostOne({
props: ["Error", "ErrorPath"],
errorCode: StateMachineErrorCode.FailErrorProperty,
}),
},
])
);
}
Expand Down

0 comments on commit 7dc622e

Please sign in to comment.