Skip to main content

peft_rs/
error.rs

1//! Error types for peft-rs.
2
3use thiserror::Error;
4
5/// Result type alias for peft-rs operations.
6pub type Result<T> = std::result::Result<T, PeftError>;
7
8/// Errors that can occur in peft-rs operations.
9#[derive(Error, Debug)]
10#[non_exhaustive]
11pub enum PeftError {
12    /// Invalid configuration parameter.
13    #[error("invalid configuration: {0}")]
14    InvalidConfig(String),
15
16    /// Shape mismatch in tensor operation.
17    #[error("shape mismatch: expected {expected:?}, got {actual:?}")]
18    ShapeMismatch {
19        /// Expected shape
20        expected: Vec<usize>,
21        /// Actual shape
22        actual: Vec<usize>,
23    },
24
25    /// Dimension mismatch.
26    #[error("dimension mismatch: {message}")]
27    DimensionMismatch {
28        /// Descriptive message
29        message: String,
30    },
31
32    /// Adapter not found.
33    #[error("adapter not found: {name}")]
34    AdapterNotFound {
35        /// Name of the missing adapter
36        name: String,
37    },
38
39    /// Adapter already exists.
40    #[error("adapter already exists: {name}")]
41    AdapterExists {
42        /// Name of the duplicate adapter
43        name: String,
44    },
45
46    /// Weight loading error.
47    #[error("failed to load weights: {0}")]
48    WeightLoad(String),
49
50    /// I/O error (file operations, serialization, etc.).
51    #[error("I/O error: {0}")]
52    Io(String),
53
54    /// Device mismatch.
55    #[error("device mismatch: tensors must be on the same device")]
56    DeviceMismatch,
57
58    /// Underlying candle error.
59    #[error("candle error: {0}")]
60    Candle(#[from] candle_core::Error),
61}