1use std::fmt;
4
5#[derive(Debug)]
7#[non_exhaustive]
8pub enum Error {
9 Io(std::io::Error),
12 Serialize(rustorb_typesupport::Error),
14 Dynamic(rustorb_xtypes::Error),
17 AlreadyDeleted,
19 OutOfResources,
21 Timeout,
25 PreconditionNotMet,
28 Unsupported(&'static str),
30 Security(String),
33}
34
35impl fmt::Display for Error {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Error::Io(e) => write!(f, "I/O error: {e}"),
39 Error::Serialize(e) => write!(f, "cannot serialize the sample: {e}"),
40 Error::Dynamic(e) => write!(f, "dynamic type or data: {e}"),
41 Error::AlreadyDeleted => f.write_str("the participant was deleted"),
42 Error::OutOfResources => f.write_str("no more entity ids"),
43 Error::Timeout => f.write_str("timed out"),
44 Error::PreconditionNotMet => f.write_str("the instance is not registered"),
45 Error::Unsupported(what) => write!(f, "not supported: {what}"),
46 Error::Security(what) => write!(f, "security: {what}"),
47 }
48 }
49}
50
51impl std::error::Error for Error {
52 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
53 match self {
54 Error::Io(e) => Some(e),
55 Error::Serialize(e) => Some(e),
56 Error::Dynamic(e) => Some(e),
57 _ => None,
58 }
59 }
60}
61
62impl From<std::io::Error> for Error {
63 fn from(e: std::io::Error) -> Self {
64 Error::Io(e)
65 }
66}
67
68impl From<rustorb_typesupport::Error> for Error {
69 fn from(e: rustorb_typesupport::Error) -> Self {
70 Error::Serialize(e)
71 }
72}
73
74impl From<rustorb_xtypes::Error> for Error {
75 fn from(e: rustorb_xtypes::Error) -> Self {
76 Error::Dynamic(e)
77 }
78}
79
80pub type Result<T> = std::result::Result<T, Error>;