Create ElementWorkflow Failure

Create Element

Workflow Failure

Learn how to create the workflow failure and understand how it fits into the system.


Workflow Failure

We'll create a type that represents the error that occurs when a branch label is empty, and we'll update the following file to include it:

// src/shared/kits/workflow/mvc/model/workflow/failure.ts

export type Failure =
  | StartFailure
  | AddTopFailure
  | EndFailure
  | ElementFailure;

export type StartFailure = {
  type: "start";
  node: "start";
  message: string;
};

export type AddTopFailure = {
  type: "addTop";
  node: "addTop";
  message: string;
};

export type EndFailure = {
  type: "end";
  node: "end";
  message: string;
};

export type ElementFailure =
  | ActionFailure
  | ConditionFailure
  | SwitchFailure
  | LoopFailure
  | ParallelFailure;

export type ActionFailure = {
  type: "element";
  element: "action";
  id: string;
  node: string;
  message: string;
};

export type ConditionFailure = {
  type: "element";
  element: "condition";
  id: string;
  node: string;
  message: string;
};

export type SwitchFailure = {
  type: "element";
  element: "switch";
  id: string;
  branch: number;
  node: string;
  message: string;
};

export type LoopFailure = {
  type: "element";
  element: "loop";
  id: string;
  node: string;
  message: string;
};

export type ParallelFailure = {
  type: "element";
  element: "parallel";
  id: string;
  branch: number;
  node: string;
  message: string;
};

We'll also update the following file to export the type we created:

// src/shared/kits/workflow/mvc/model/workflow/index.ts
import type {
  WorkflowFlow,
  ElementFlow,
  ActionFlow,
  ConditionFlow,
  SwitchFlow,
  LoopFlow,
  ParallelFlow,
} from "./flow";

import type {
  Widget,
  GlobalWidget,
  StartInfoWidget,
  EndInfoWidget,
  AddTopWidget,
  ElementWidget,
  ElementAddNextWidget,
  ElementTypeWidget,
  ActionWidget,
  ActionInfoWidget,
  ConditionWidget,
  ConditionInfoWidget,
  ConditionAddThenWidget,
  ConditionAddElseWidget,
  SwitchWidget,
  SwitchBranchInfoWidget,
  SwitchCreateBranchWidget,
  SwitchAddBranchWidget,
  SwitchAddDefaultWidget,
  LoopWidget,
  LoopInfoWidget,
  LoopAddIntoWidget,
  ParallelWidget,
  ParallelCreateBranchWidget,
  ParallelBranchInfoWidget,
  ParallelAddBranchWidget,
} from "./widget";

import type {
  Failure,
  StartFailure,
  AddTopFailure,
  EndFailure,
  ElementFailure,
  ActionFailure,
  ConditionFailure,
  SwitchFailure,
  LoopFailure,
} from "./failure";

export interface Workflow {
  flow: WorkflowFlow;
  widget: Widget | null;
  active: string | null; // String that identifies the active selection.
  failure: Failure | null; // Failure that occurred in the workflow.
}

export type {
  WorkflowFlow,
  ElementFlow,
  ActionFlow,
  ConditionFlow,
  SwitchFlow,
  LoopFlow,
  ParallelFlow,
};

export type {
  Widget,
  GlobalWidget,
  StartInfoWidget,
  EndInfoWidget,
  AddTopWidget,
  ElementWidget,
  ElementAddNextWidget,
  ElementTypeWidget,
  ActionWidget,
  ActionInfoWidget,
  ConditionWidget,
  ConditionInfoWidget,
  ConditionAddThenWidget,
  ConditionAddElseWidget,
  SwitchWidget,
  SwitchBranchInfoWidget,
  SwitchCreateBranchWidget,
  SwitchAddBranchWidget,
  SwitchAddDefaultWidget,
  LoopWidget,
  LoopInfoWidget,
  LoopAddIntoWidget,
  ParallelWidget,
  ParallelCreateBranchWidget,
  ParallelBranchInfoWidget,
  ParallelAddBranchWidget,
};

export type {
  Failure,
  StartFailure,
  AddTopFailure,
  EndFailure,
  ElementFailure,
  ActionFailure,
  ConditionFailure,
  SwitchFailure,
  LoopFailure,
};