victauri_core/error.rs
1//! Typed error enum for the `victauri-core` crate.
2
3use std::fmt;
4
5/// Errors that can occur within `victauri-core` operations.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum VictauriError {
9 /// A capacity limit (event log, checkpoints, etc.) was exceeded.
10 #[error("capacity limit exceeded: {message}")]
11 CapacityExceeded {
12 /// Description of which capacity was exceeded.
13 message: String,
14 },
15
16 /// JSON serialization or deserialization failed.
17 #[error("serialization error: {0}")]
18 Serialization(#[from] serde_json::Error),
19
20 /// An input parameter was invalid or out of range.
21 #[error("invalid input: {message}")]
22 InvalidInput {
23 /// Description of what was invalid.
24 message: String,
25 },
26
27 /// Attempted an operation that requires an active recording session.
28 #[error("no active recording session")]
29 NoActiveRecording,
30
31 /// Attempted to start a recording when one is already active.
32 #[error("recording session already active")]
33 RecordingAlreadyActive,
34
35 /// Referenced a checkpoint ID that does not exist.
36 #[error("checkpoint not found: {id}")]
37 CheckpointNotFound {
38 /// The checkpoint ID that was not found.
39 id: String,
40 },
41
42 /// Referenced a command name that is not registered.
43 #[error("command not found: {name}")]
44 CommandNotFound {
45 /// The command name that was not found.
46 name: String,
47 },
48
49 /// Referenced a ref handle that is invalid or expired.
50 #[error("invalid ref handle: {ref_id}")]
51 InvalidRefHandle {
52 /// The ref handle ID that was invalid.
53 ref_id: String,
54 },
55
56 /// Used an assertion condition that is not recognized.
57 #[error("unknown assertion condition: {condition}")]
58 UnknownCondition {
59 /// The condition string that was not recognized.
60 condition: String,
61 },
62}
63
64/// Convenience alias for `std::result::Result<T, VictauriError>`.
65pub type Result<T> = std::result::Result<T, VictauriError>;
66
67impl VictauriError {
68 /// Create a [`CapacityExceeded`](Self::CapacityExceeded) error.
69 #[must_use]
70 pub fn capacity_exceeded(message: impl fmt::Display) -> Self {
71 Self::CapacityExceeded {
72 message: message.to_string(),
73 }
74 }
75 /// Create an [`InvalidInput`](Self::InvalidInput) error.
76 #[must_use]
77 pub fn invalid_input(message: impl fmt::Display) -> Self {
78 Self::InvalidInput {
79 message: message.to_string(),
80 }
81 }
82}