gpsd_json/error.rs
1//! Error types for GPSD JSON protocol operations
2//!
3//! This module defines the error types that can occur when communicating
4//! with GPSD or parsing its JSON protocol messages.
5
6/// Main error type for GPSD JSON protocol operations
7///
8/// This enum represents all possible errors that can occur during
9/// communication with GPSD or while parsing protocol messages.
10#[derive(Debug)]
11pub enum GpsdJsonError {
12 /// I/O error occurred during network communication
13 ///
14 /// This typically happens when the connection to GPSD is lost,
15 /// the server is unreachable, or there are network-related issues.
16 IoError(std::io::Error),
17
18 /// JSON serialization/deserialization error
19 ///
20 /// Occurs when GPSD sends malformed JSON or when the response
21 /// doesn't match the expected message structure.
22 SerdeError(serde_json::Error),
23
24 /// GPSD protocol version is not supported
25 ///
26 /// The tuple contains (major, minor) version numbers.
27 /// This library requires protocol version 3.x compatibility.
28 UnsupportedProtocolVersion((i32, i32)),
29
30 /// Protocol-level error
31 ///
32 /// Indicates an error in the GPSD protocol communication,
33 /// such as unexpected message sequences or missing required responses.
34 ProtocolError(&'static str),
35}
36
37impl core::fmt::Display for GpsdJsonError {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 match self {
40 GpsdJsonError::IoError(err) => write!(f, "IoError: {err}"),
41 GpsdJsonError::SerdeError(err) => write!(f, "SerdeError: {err}"),
42 GpsdJsonError::UnsupportedProtocolVersion((major, minor)) => {
43 write!(f, "UnsupportedProtocolVersion: {major}.{minor}")
44 }
45 GpsdJsonError::ProtocolError(msg) => write!(f, "ProtocolError: {msg}"),
46 }
47 }
48}
49
50impl core::error::Error for GpsdJsonError {}