edgefirst_client/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright © 2025 Au-Zone Technologies. All Rights Reserved.
3
4use crate::Progress;
5use tokio::sync::{AcquireError, watch};
6
7/// Comprehensive error type for EdgeFirst Studio Client operations.
8///
9/// This enum covers all possible error conditions that can occur when using
10/// the EdgeFirst Studio Client, from network issues to authentication problems
11/// and data validation errors.
12#[derive(Debug)]
13pub enum Error {
14    /// An I/O error occurred during file operations.
15    IoError(std::io::Error),
16    /// Configuration parsing or loading error.
17    ConfigError(config::ConfigError),
18    /// JSON serialization or deserialization error.
19    JsonError(serde_json::Error),
20    /// HTTP request error from the reqwest client.
21    HttpError(reqwest::Error),
22    /// Maximum number of retries exceeded for an operation.
23    MaxRetriesExceeded(u32),
24    /// URL parsing error.
25    UrlParseError(url::ParseError),
26    /// RPC error with error code and message from the server.
27    RpcError(i32, String),
28    /// Invalid RPC request ID format.
29    InvalidRpcId(String),
30    /// Environment variable error.
31    EnvError(std::env::VarError),
32    /// Semaphore acquisition error for concurrent operations.
33    SemaphoreError(AcquireError),
34    /// Async task join error.
35    JoinError(tokio::task::JoinError),
36    /// Error sending progress updates.
37    ProgressSendError(watch::error::SendError<Progress>),
38    /// Error receiving progress updates.
39    ProgressRecvError(watch::error::RecvError),
40    /// Path prefix stripping error.
41    StripPrefixError(std::path::StripPrefixError),
42    /// Integer parsing error.
43    ParseIntError(std::num::ParseIntError),
44    /// Server returned an invalid or unexpected response.
45    InvalidResponse,
46    /// Requested functionality is not yet implemented.
47    NotImplemented,
48    /// File part size exceeds the maximum allowed limit.
49    PartTooLarge,
50    /// Invalid annotation type provided.
51    InvalidAnnotationType(String),
52    /// Required image files are missing from the dataset.
53    MissingImages(String),
54    /// Required annotation files are missing from the dataset.
55    MissingAnnotations(String),
56    /// Referenced label is missing or not found.
57    MissingLabel(String),
58    /// Invalid parameters provided to an operation.
59    InvalidParameters(String),
60    /// Attempted to use a feature that is not enabled.
61    FeatureNotEnabled(String),
62    /// Authentication token is empty or not provided.
63    EmptyToken,
64    /// Authentication token format is invalid.
65    InvalidToken,
66    /// Authentication token has expired.
67    TokenExpired,
68    /// User is not authorized to perform the requested operation.
69    Unauthorized,
70}
71
72impl From<std::io::Error> for Error {
73    fn from(err: std::io::Error) -> Self {
74        Error::IoError(err)
75    }
76}
77
78impl From<config::ConfigError> for Error {
79    fn from(err: config::ConfigError) -> Self {
80        Error::ConfigError(err)
81    }
82}
83
84impl From<serde_json::Error> for Error {
85    fn from(err: serde_json::Error) -> Self {
86        Error::JsonError(err)
87    }
88}
89
90impl From<reqwest::Error> for Error {
91    fn from(err: reqwest::Error) -> Self {
92        Error::HttpError(err)
93    }
94}
95
96impl From<url::ParseError> for Error {
97    fn from(err: url::ParseError) -> Self {
98        Error::UrlParseError(err)
99    }
100}
101
102impl From<std::env::VarError> for Error {
103    fn from(err: std::env::VarError) -> Self {
104        Error::EnvError(err)
105    }
106}
107
108impl From<AcquireError> for Error {
109    fn from(err: AcquireError) -> Self {
110        Error::SemaphoreError(err)
111    }
112}
113
114impl From<tokio::task::JoinError> for Error {
115    fn from(err: tokio::task::JoinError) -> Self {
116        Error::JoinError(err)
117    }
118}
119
120impl From<watch::error::SendError<Progress>> for Error {
121    fn from(err: watch::error::SendError<Progress>) -> Self {
122        Error::ProgressSendError(err)
123    }
124}
125
126impl From<watch::error::RecvError> for Error {
127    fn from(err: watch::error::RecvError) -> Self {
128        Error::ProgressRecvError(err)
129    }
130}
131
132impl From<std::path::StripPrefixError> for Error {
133    fn from(err: std::path::StripPrefixError) -> Self {
134        Error::StripPrefixError(err)
135    }
136}
137
138impl From<std::num::ParseIntError> for Error {
139    fn from(err: std::num::ParseIntError) -> Self {
140        Error::ParseIntError(err)
141    }
142}