Skip to main content

nemo_flow_adaptive/
error.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error types for the nemo-flow-adaptive crate.
5
6use nemo_flow::plugin::PluginError;
7use thiserror::Error;
8
9/// The error type for all nemo-flow-adaptive operations.
10#[derive(Debug, Error)]
11pub enum AdaptiveError {
12    /// Configuration validation failed.
13    #[error("invalid config: {0}")]
14    InvalidConfig(String),
15
16    /// The requested resource was not found.
17    #[error("not found: {0}")]
18    NotFound(String),
19
20    /// A storage operation failed.
21    #[error("storage error: {0}")]
22    Storage(String),
23
24    /// A serialization or deserialization error.
25    #[error("serialization error: {0}")]
26    Serialization(serde_json::Error),
27
28    /// An internal error (e.g., lock poisoning).
29    #[error("internal error: {0}")]
30    Internal(String),
31
32    /// A registration with the NeMo Flow runtime failed.
33    #[error("registration failed: {0}")]
34    RegistrationFailed(String),
35
36    /// The internal telemetry channel was closed unexpectedly.
37    #[error("channel closed: {0}")]
38    ChannelClosed(String),
39
40    /// A Redis operation failed.
41    #[cfg(feature = "redis-backend")]
42    #[error("redis error: {0}")]
43    Redis(#[from] redis::RedisError),
44}
45
46impl From<serde_json::Error> for AdaptiveError {
47    fn from(value: serde_json::Error) -> Self {
48        Self::Serialization(value)
49    }
50}
51
52impl From<PluginError> for AdaptiveError {
53    fn from(value: PluginError) -> Self {
54        match value {
55            PluginError::InvalidConfig(message) => Self::InvalidConfig(message),
56            PluginError::NotFound(message) => Self::NotFound(message),
57            PluginError::Serialization(err) => Self::Serialization(err),
58            PluginError::Internal(message) => Self::Internal(message),
59            PluginError::RegistrationFailed(message) => Self::RegistrationFailed(message),
60        }
61    }
62}
63
64/// A specialized [`Result`](std::result::Result) type for nemo-flow-adaptive operations.
65pub type Result<T> = std::result::Result<T, AdaptiveError>;
66
67#[cfg(test)]
68#[path = "../tests/coverage/error_tests.rs"]
69mod tests;