Skip to main content

snap7_client/
error.rs

1use crate::proto::ProtoError;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum Error {
6    #[error("protocol error: {0}")]
7    Proto(#[from] ProtoError),
8
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    #[error("PLC error: code={code:#06x} ({message})")]
13    PlcError { code: u32, message: String },
14
15    #[error("connection timeout after {0:?}")]
16    Timeout(std::time::Duration),
17
18    #[error("PDU negotiation failed")]
19    NegotiationFailed,
20
21    #[error("connection refused or PLC not responding")]
22    ConnectionRefused,
23
24    #[error("unexpected response PDU type")]
25    UnexpectedResponse,
26}
27
28pub type Result<T> = std::result::Result<T, Error>;