1use thiserror::Error;
4
5use crate::types::MotorErrorKind;
6
7#[derive(Debug, Error)]
8pub enum Error {
9 #[error("CAN transport: {0}")]
10 Transport(#[from] can_transport::CanIoError),
11
12 #[error("SDO: {0}")]
13 Sdo(#[from] canopen_sdo::asynch::AsyncSdoError),
14
15 #[error("unknown node {0}")]
16 UnknownNode(u8),
17
18 #[error("invalid node id {0} (must be 1..=127)")]
19 InvalidNodeId(u8),
20
21 #[error("invalid COB-ID 0x{cob_id:X}: {reason}")]
22 InvalidCobId { cob_id: u16, reason: &'static str },
23
24 #[error("motor reported error: {0:?}")]
25 InErrorState(MotorErrorKind),
26
27 #[error("nid 0x{nid:02X} not ready (lifecycle = {lifecycle})")]
28 NotReady { nid: u8, lifecycle: String },
29
30 #[error("target `{given}` does not match current mode `{expected}`")]
31 TargetModeMismatch {
32 expected: String,
33 given: &'static str,
34 },
35
36 #[error("set_mode confirmation timed out (waiting for TPDO feedback)")]
37 ModeConfirmTimeout,
38
39 #[error("internal: {0}")]
40 Internal(String),
41}
42
43pub type Result<T> = std::result::Result<T, Error>;