attuned_core/
error.rs

1//! Error types for Attuned.
2
3use thiserror::Error;
4
5/// Top-level error type for Attuned operations.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum AttunedError {
9    /// Validation error for input data.
10    #[error("validation error: {0}")]
11    Validation(#[from] ValidationError),
12
13    /// Storage-related error.
14    #[error("storage error: {0}")]
15    Storage(String),
16
17    /// Serialization/deserialization error.
18    #[error("serialization error: {0}")]
19    Serialization(#[from] serde_json::Error),
20}
21
22/// Validation errors for state data.
23#[derive(Debug, Error, PartialEq)]
24#[non_exhaustive]
25pub enum ValidationError {
26    /// Axis value is outside the valid range [0.0, 1.0].
27    #[error("axis '{axis}' has value {value} outside valid range [0.0, 1.0]")]
28    AxisOutOfRange {
29        /// The axis name.
30        axis: String,
31        /// The invalid value.
32        value: f32,
33    },
34
35    /// Axis name contains invalid characters.
36    #[error("axis name '{axis}' contains invalid characters (must be lowercase alphanumeric with underscores)")]
37    InvalidAxisName {
38        /// The invalid axis name.
39        axis: String,
40    },
41
42    /// User ID is empty.
43    #[error("user_id cannot be empty")]
44    EmptyUserId,
45
46    /// User ID exceeds maximum length.
47    #[error("user_id exceeds maximum length of {max} characters")]
48    UserIdTooLong {
49        /// Maximum allowed length.
50        max: usize,
51    },
52
53    /// User ID contains invalid characters.
54    #[error("user_id contains invalid characters (must be alphanumeric, underscore, or hyphen)")]
55    InvalidUserIdChars,
56
57    /// Confidence value is outside valid range.
58    #[error("confidence {value} is outside valid range [0.0, 1.0]")]
59    ConfidenceOutOfRange {
60        /// The invalid confidence value.
61        value: f32,
62    },
63
64    /// Missing required field.
65    #[error("missing required field: {field}")]
66    MissingField {
67        /// The missing field name.
68        field: String,
69    },
70}