ntrip_core/
error.rs

1//! Error types for ntrip-core.
2
3use thiserror::Error;
4
5/// Errors that can occur during NTRIP operations.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// Failed to connect to the NTRIP caster.
10    #[error("Failed to connect to {host}:{port}: {source}")]
11    ConnectionFailed {
12        host: String,
13        port: u16,
14        #[source]
15        source: std::io::Error,
16    },
17
18    /// Connection timed out.
19    #[error("Connection timed out after {timeout_secs} seconds")]
20    Timeout { timeout_secs: u32 },
21
22    /// Read timed out - no data received within configured period.
23    #[error("Read timed out after {timeout_secs} seconds - no data received")]
24    ReadTimeout { timeout_secs: u32 },
25
26    /// Authentication failed.
27    #[error("Authentication failed for {host} (user: {username})")]
28    AuthenticationFailed { host: String, username: String },
29
30    /// Mountpoint not found on the caster.
31    #[error("Mountpoint '{mountpoint}' not found on {host}")]
32    MountpointNotFound { host: String, mountpoint: String },
33
34    /// HTTP error response from server.
35    #[error("HTTP error from {host}: {status_code} {reason}")]
36    HttpError {
37        host: String,
38        status_code: u16,
39        reason: String,
40    },
41
42    /// TLS/HTTPS error.
43    #[error("TLS error: {message}")]
44    TlsError { message: String },
45
46    /// Network I/O error.
47    #[error("Network error: {source}")]
48    NetworkError {
49        #[source]
50        source: std::io::Error,
51    },
52
53    /// Stream disconnected.
54    #[error("Stream disconnected: {reason}")]
55    StreamDisconnected { reason: String },
56
57    /// Invalid configuration.
58    #[error("Invalid configuration: {message}")]
59    InvalidConfig { message: String },
60
61    /// Failed to parse sourcetable.
62    #[error("Failed to parse sourcetable: {message}")]
63    SourcetableParseError { message: String },
64
65    /// Proxy connection or tunnel establishment failed.
66    #[error("Proxy error: {message}")]
67    ProxyError { message: String },
68}
69
70impl Error {
71    /// Create a connection failed error.
72    pub fn connection_failed(host: &str, port: u16, source: std::io::Error) -> Self {
73        Self::ConnectionFailed {
74            host: host.to_string(),
75            port,
76            source,
77        }
78    }
79}