1use std::{fmt, io};
5
6#[derive(Debug)]
8pub enum TraciError {
9 Connection(io::Error),
11
12 Protocol(String),
15
16 SimulationError(String),
18
19 NotImplemented(String),
21
22 SimulationEnd,
25}
26
27impl fmt::Display for TraciError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 TraciError::Connection(e) => write!(f, "TraCI connection error: {e}"),
31 TraciError::Protocol(msg) => write!(f, "TraCI protocol error: {msg}"),
32 TraciError::SimulationError(msg) => write!(f, "TraCI simulation error: {msg}"),
33 TraciError::NotImplemented(msg) => write!(f, "TraCI command not implemented: {msg}"),
34 TraciError::SimulationEnd => write!(f, "SUMO simulation ended"),
35 }
36 }
37}
38
39impl std::error::Error for TraciError {
40 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
41 match self {
42 TraciError::Connection(e) => Some(e),
43 _ => None,
44 }
45 }
46}
47
48impl From<io::Error> for TraciError {
49 fn from(e: io::Error) -> Self {
50 TraciError::Connection(e)
51 }
52}