Skip to content

Commit

Permalink
Update invalid command message (#2468)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminc authored Feb 6, 2022
1 parent 8f88254 commit b2c7ee1
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions service/history/commandChecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,43 +781,32 @@ func (v *commandAttrValidator) createCrossNamespaceCallError(
func (v *commandAttrValidator) validateCommandSequence(
commands []*commandpb.Command,
) error {
encounterTerminalCommand := false
closeCommand := enumspb.COMMAND_TYPE_UNSPECIFIED

for _, command := range commands {
if encounterTerminalCommand {
if closeCommand != enumspb.COMMAND_TYPE_UNSPECIFIED {
return serviceerror.NewInvalidArgument(fmt.Sprintf(
"encouter invalid commands sequence: %v",
strings.Join(v.commandTypes(commands), ", "),
"invalid command sequence: [%v], command %s must be the last command.",
strings.Join(v.commandTypes(commands), ", "), closeCommand.String(),
))
}

switch command.GetCommandType() {
case enumspb.COMMAND_TYPE_SCHEDULE_ACTIVITY_TASK:
case enumspb.COMMAND_TYPE_SCHEDULE_ACTIVITY_TASK,
enumspb.COMMAND_TYPE_REQUEST_CANCEL_ACTIVITY_TASK,
enumspb.COMMAND_TYPE_START_TIMER,
enumspb.COMMAND_TYPE_CANCEL_TIMER,
enumspb.COMMAND_TYPE_RECORD_MARKER,
enumspb.COMMAND_TYPE_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION,
enumspb.COMMAND_TYPE_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION,
enumspb.COMMAND_TYPE_START_CHILD_WORKFLOW_EXECUTION,
enumspb.COMMAND_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES:
// noop
case enumspb.COMMAND_TYPE_REQUEST_CANCEL_ACTIVITY_TASK:
// noop
case enumspb.COMMAND_TYPE_START_TIMER:
// noop
case enumspb.COMMAND_TYPE_CANCEL_TIMER:
// noop
case enumspb.COMMAND_TYPE_RECORD_MARKER:
// noop
case enumspb.COMMAND_TYPE_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION:
// noop
case enumspb.COMMAND_TYPE_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION:
// noop
case enumspb.COMMAND_TYPE_START_CHILD_WORKFLOW_EXECUTION:
// noop
case enumspb.COMMAND_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES:
// noop
case enumspb.COMMAND_TYPE_CONTINUE_AS_NEW_WORKFLOW_EXECUTION:
encounterTerminalCommand = true
case enumspb.COMMAND_TYPE_COMPLETE_WORKFLOW_EXECUTION:
encounterTerminalCommand = true
case enumspb.COMMAND_TYPE_FAIL_WORKFLOW_EXECUTION:
encounterTerminalCommand = true
case enumspb.COMMAND_TYPE_CANCEL_WORKFLOW_EXECUTION:
encounterTerminalCommand = true
case enumspb.COMMAND_TYPE_CONTINUE_AS_NEW_WORKFLOW_EXECUTION,
enumspb.COMMAND_TYPE_COMPLETE_WORKFLOW_EXECUTION,
enumspb.COMMAND_TYPE_FAIL_WORKFLOW_EXECUTION,
enumspb.COMMAND_TYPE_CANCEL_WORKFLOW_EXECUTION:
closeCommand = command.GetCommandType()
default:
return serviceerror.NewInvalidArgument(fmt.Sprintf("unknown command type: %v", command.GetCommandType()))
}
Expand Down

0 comments on commit b2c7ee1

Please sign in to comment.