screeps_async/
error.rs

1//! Errors emitted by screeps-async
2use std::fmt::{Debug, Display, Formatter};
3
4/// An Error returned by the [crate::runtime::ScreepsRuntime]
5#[derive(Debug, Eq, PartialEq, Copy, Clone)]
6#[non_exhaustive]
7pub enum RuntimeError {
8    /// The allocated time this tick has already been consumed
9    OutOfTime,
10    /// The runtime has detected that deadlock has occurred.
11    /// This usually means you tried to [block_on](crate::block_on) a future that [delay](crate::time::delay_ticks)s
12    /// across ticks
13    DeadlockDetected,
14}
15
16impl Display for RuntimeError {
17    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18        match self {
19            RuntimeError::OutOfTime => {
20                write!(f, "Ran out of allocated time this tick")
21            }
22            RuntimeError::DeadlockDetected => {
23                write!(f, "Async runtime has been deadlocked")
24            }
25        }
26    }
27}
28
29impl std::error::Error for RuntimeError {}