Skip to content

Commit cf301eb

Browse files
fix(core): Relax validation of custom process states
The last release caused an error to be thrown on bootstrap in the case of unreachable states. There are however valid cases for making states unreachable, so now we will just print a warning.
1 parent f01533a commit cf301eb

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

packages/core/src/common/finite-state-machine/validate-transition-definition.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('FSM validateTransitionDefinition()', () => {
7474

7575
const result = validateTransitionDefinition(valid, 'Start');
7676

77-
expect(result.valid).toBe(false);
77+
expect(result.valid).toBe(true);
7878
expect(result.error).toBe('The following states are unreachable: Unreachable');
7979
});
8080

packages/core/src/common/finite-state-machine/validate-transition-definition.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,15 @@ export function validateTransitionDefinition<T extends string>(
5353
};
5454
}
5555

56-
if (!allStatesReached()) {
57-
return {
58-
valid: false,
59-
error: `The following states are unreachable: ${Object.entries(result)
60-
.filter(([s, v]) => !(v as ValidationResult).reachable)
61-
.map(([s]) => s)
62-
.join(', ')}`,
63-
};
64-
} else {
65-
return {
66-
valid: true,
67-
};
68-
}
56+
const error = !allStatesReached()
57+
? `The following states are unreachable: ${Object.entries(result)
58+
.filter(([s, v]) => !(v as ValidationResult).reachable)
59+
.map(([s]) => s)
60+
.join(', ')}`
61+
: undefined;
62+
63+
return {
64+
valid: true,
65+
error,
66+
};
6967
}

packages/core/src/service/helpers/fulfillment-state-machine/fulfillment-state-machine.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export class FulfillmentStateMachine {
6363
Logger.error(`The fulfillment process has an invalid configuration:`);
6464
throw new Error(validationResult.error);
6565
}
66+
if (validationResult.valid && validationResult.error) {
67+
Logger.warn(`Fulfillment process: ${validationResult.error}`);
68+
}
6669
return {
6770
transitions: allTransitions,
6871
onTransitionStart: async (fromState, toState, data) => {

packages/core/src/service/helpers/order-state-machine/order-state-machine.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export class OrderStateMachine {
5656
Logger.error(`The order process has an invalid configuration:`);
5757
throw new Error(validationResult.error);
5858
}
59+
if (validationResult.valid && validationResult.error) {
60+
Logger.warn(`Order process: ${validationResult.error}`);
61+
}
5962
return {
6063
transitions: allTransitions,
6164
onTransitionStart: async (fromState, toState, data) => {

packages/core/src/service/helpers/payment-state-machine/payment-state-machine.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export class PaymentStateMachine {
5858
Logger.error(`The payment process has an invalid configuration:`);
5959
throw new Error(validationResult.error);
6060
}
61+
if (validationResult.valid && validationResult.error) {
62+
Logger.warn(`Payment process: ${validationResult.error}`);
63+
}
6164
return {
6265
transitions: allTransitions,
6366
onTransitionStart: async (fromState, toState, data) => {

0 commit comments

Comments
 (0)