auths_core/pairing/
error.rs1use auths_crypto::AuthsErrorInfo;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum PairingError {
11 #[error(transparent)]
13 Protocol(#[from] auths_pairing_protocol::ProtocolError),
14
15 #[error("QR code generation failed: {0}")]
17 QrCodeFailed(String),
18
19 #[error("Relay error: {0}")]
21 RelayError(String),
22
23 #[error("Local server error: {0}")]
25 LocalServerError(String),
26
27 #[error("mDNS error: {0}")]
29 MdnsError(String),
30
31 #[error("No peer found on local network")]
33 NoPeerFound,
34
35 #[error("LAN pairing timed out")]
37 LanTimeout,
38}
39
40impl AuthsErrorInfo for PairingError {
41 fn error_code(&self) -> &'static str {
42 match self {
43 Self::Protocol(_) => "AUTHS-E3201",
44 Self::QrCodeFailed(_) => "AUTHS-E3202",
45 Self::RelayError(_) => "AUTHS-E3203",
46 Self::LocalServerError(_) => "AUTHS-E3204",
47 Self::MdnsError(_) => "AUTHS-E3205",
48 Self::NoPeerFound => "AUTHS-E3206",
49 Self::LanTimeout => "AUTHS-E3207",
50 }
51 }
52
53 fn suggestion(&self) -> Option<&'static str> {
54 match self {
55 Self::NoPeerFound => Some("Ensure both devices are on the same network"),
56 Self::LanTimeout => Some("Check your network and try again"),
57 Self::RelayError(_) => Some("Check your internet connection"),
58 Self::Protocol(_) => Some("Ensure both devices are running compatible auths versions"),
59 Self::QrCodeFailed(_) => {
60 Some("QR code generation failed; try `auths device pair --mode relay` instead")
61 }
62 Self::LocalServerError(_) => {
63 Some("The local pairing server failed to start; check that the port is available")
64 }
65 Self::MdnsError(_) => {
66 Some("mDNS discovery failed; try `auths device pair --mode relay` instead")
67 }
68 }
69 }
70}
71
72impl From<serde_json::Error> for PairingError {
73 fn from(e: serde_json::Error) -> Self {
74 PairingError::Protocol(auths_pairing_protocol::ProtocolError::Serialization(
75 e.to_string(),
76 ))
77 }
78}