Skip to main content

subtr_actor/
error.rs

1use crate::*;
2use std::backtrace::Backtrace;
3use thiserror::Error;
4
5/// [`SubtrActorErrorVariant`] is an enumeration of all the specific error
6/// variants that can occur while processing game replays in the subtr-actor
7/// domain. These include errors related to network frames, frame indexing,
8/// player sets, actor states, object ids, team identities, and data types
9/// amongst others.
10#[derive(Error, Debug, Clone)]
11pub enum SubtrActorErrorVariant {
12    #[error("Replay has no network frames")]
13    NoNetworkFrames,
14
15    #[error("Frame index out of bounds")]
16    FrameIndexOutOfBounds,
17
18    #[error("Players found in frames that were not part of original set. Found: {found:?}, Original: {original:?}")]
19    InconsistentPlayerSet {
20        found: std::collections::HashSet<PlayerId>,
21        original: std::collections::HashSet<PlayerId>,
22    },
23
24    #[error(
25        "No update for ActorId {actor_id:?} of ObjectId {object_id:?} after frame {frame_index}"
26    )]
27    NoUpdateAfterFrame {
28        actor_id: boxcars::ActorId,
29        object_id: boxcars::ObjectId,
30        frame_index: usize,
31    },
32
33    #[error("No boost amount value.")]
34    NoBoostAmountValue,
35
36    #[error("The attribute value that was found was not of the expected type {expected_type} {actual_type:?}")]
37    UnexpectedAttributeType {
38        expected_type: &'static str,
39        actual_type: &'static str,
40    },
41
42    #[error("ActorId {actor_id:?} has no matching player id")]
43    NoMatchingPlayerId { actor_id: boxcars::ActorId },
44
45    #[error("No game actor")]
46    NoGameActor,
47
48    #[error("ActorId {actor_id:} already exists with object_id {object_id:}")]
49    ActorIdAlreadyExists {
50        actor_id: boxcars::ActorId,
51        object_id: boxcars::ObjectId,
52    },
53
54    #[error("{name:?} actor for player {player_id:?} not found")]
55    ActorNotFound {
56        name: &'static str,
57        player_id: PlayerId,
58    },
59
60    #[error("There was no actor state for actor_id: {actor_id:?}")]
61    NoStateForActorId { actor_id: boxcars::ActorId },
62
63    #[error("Couldn't find object id for {name}")]
64    ObjectIdNotFound { name: &'static str },
65
66    #[error("No value found for derived key {name:?}")]
67    DerivedKeyValueNotFound { name: String },
68
69    #[error("Ball actor not found")]
70    BallActorNotFound,
71
72    #[error("Player team unknown, {player_id:?}")]
73    UnknownPlayerTeam { player_id: PlayerId },
74
75    #[error("Team object id not known {object_id:?}, for player {player_id:?}")]
76    UnknownTeamObjectId {
77        object_id: boxcars::ObjectId,
78        player_id: PlayerId,
79    },
80
81    #[error("Team name was empty for {player_id:?}")]
82    EmptyTeamName { player_id: PlayerId },
83
84    #[error("Error returned to deliberately end processing early")]
85    FinishProcessingEarly,
86
87    #[error("Player stats header not found")]
88    PlayerStatsHeaderNotFound,
89
90    #[error("Interpolation time order was incorrect start_time {start_time:} {time:} {end_time:}")]
91    InterpolationTimeOrderError {
92        start_time: f32,
93        time: f32,
94        end_time: f32,
95    },
96
97    #[error("The updated actor id does not exist {update:?}")]
98    UpdatedActorIdDoesNotExist { update: boxcars::UpdatedAttribute },
99
100    #[error("Could not find {property:} in state")]
101    PropertyNotFoundInState { property: &'static str },
102
103    #[error("Could not build replay meta")]
104    CouldNotBuildReplayMeta,
105
106    #[error("Error converting float")]
107    FloatConversionError,
108
109    #[error(transparent)]
110    NDArrayShapeError(#[from] ::ndarray::ShapeError),
111
112    #[error("{0:?} was not a recognized feature adder")]
113    UnknownFeatureAdderName(String),
114
115    #[error("Callback error: {0}")]
116    CallbackError(String),
117
118    #[error("Unknown builtin stats module '{0}'")]
119    UnknownStatsModuleName(String),
120
121    #[error("Stats serialization error: {0}")]
122    StatsSerializationError(String),
123}
124
125/// [`SubtrActorError`] struct provides an error variant
126/// [`SubtrActorErrorVariant`] along with its backtrace.
127#[derive(Debug)]
128pub struct SubtrActorError {
129    pub backtrace: Backtrace,
130    pub variant: SubtrActorErrorVariant,
131}
132
133impl SubtrActorError {
134    pub fn new(variant: SubtrActorErrorVariant) -> Self {
135        Self {
136            backtrace: Backtrace::capture(),
137            variant,
138        }
139    }
140
141    pub fn new_result<T>(variant: SubtrActorErrorVariant) -> Result<T, Self> {
142        Err(Self::new(variant))
143    }
144}
145
146#[allow(clippy::result_large_err)]
147pub type SubtrActorResult<T> = Result<T, SubtrActorError>;