qubit_state_machine/standard/state_machine_build_error.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Validation errors returned when building a state machine.
11
12use std::fmt::Debug;
13
14use thiserror::Error;
15
16/// Error returned when state machine rules are internally inconsistent.
17///
18/// `S` is the state type and `E` is the event type.
19#[derive(Debug, Clone, Copy, Eq, PartialEq, Error)]
20pub enum StateMachineBuildError<S, E>
21where
22 S: Debug,
23 E: Debug,
24{
25 /// An initial state was configured but not registered as a state.
26 #[error("initial state is not registered: {state:?}")]
27 InitialStateNotRegistered {
28 /// The unregistered initial state.
29 state: S,
30 },
31 /// A final state was configured but not registered as a state.
32 #[error("final state is not registered: {state:?}")]
33 FinalStateNotRegistered {
34 /// The unregistered final state.
35 state: S,
36 },
37 /// A transition source was not registered as a state.
38 #[error("transition source is not registered: {source_state:?} --{event:?}--> {target:?}")]
39 TransitionSourceNotRegistered {
40 /// Source state of the invalid transition.
41 source_state: S,
42 /// Event of the invalid transition.
43 event: E,
44 /// Target state of the invalid transition.
45 target: S,
46 },
47 /// A transition target was not registered as a state.
48 #[error("transition target is not registered: {source_state:?} --{event:?}--> {target:?}")]
49 TransitionTargetNotRegistered {
50 /// Source state of the invalid transition.
51 source_state: S,
52 /// Event of the invalid transition.
53 event: E,
54 /// Target state of the invalid transition.
55 target: S,
56 },
57 /// Two transitions use the same `(source, event)` with different targets.
58 #[error(
59 "duplicate transition target: {source_state:?} --{event:?}--> \
60 {existing_target:?} conflicts with {new_target:?}"
61 )]
62 DuplicateTransition {
63 /// Source state shared by both transitions.
64 source_state: S,
65 /// Event shared by both transitions.
66 event: E,
67 /// Target registered first.
68 existing_target: S,
69 /// Conflicting target registered later.
70 new_target: S,
71 },
72}