use core::num::TryFromIntError; use alloc::collections::TryReserveError; use embassy_rp::rtc::RtcError; use sachy_sntp::SntpError; #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum PicoError { InvalidSntpTime(SntpError), InvalidRtcTime, AllocationError, NoisePayloadTooBig, TcpError(embassy_net::tcp::Error), NoiseProtoError, } impl core::fmt::Display for PicoError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::InvalidSntpTime(reason) => write!(f, "Invalid SNTP time: {reason:?}"), Self::InvalidRtcTime => write!(f, "Invalid RTC time: Year is out of bounds"), Self::AllocationError => write!(f, "Failed to allocate memory"), Self::NoisePayloadTooBig => write!(f, "Invalid payload size"), Self::TcpError(error) => write!(f, "Network error: {error:?}"), Self::NoiseProtoError => write!(f, "Noise protocol failure"), } } } impl core::error::Error for PicoError {} impl From for PicoError { fn from(value: SntpError) -> Self { Self::InvalidSntpTime(value) } } impl From for PicoError { fn from(_value: RtcError) -> Self { Self::InvalidRtcTime } } impl From for PicoError { fn from(_value: TryReserveError) -> Self { Self::AllocationError } } impl From for PicoError { fn from(_value: TryFromIntError) -> Self { Self::NoisePayloadTooBig } } impl From for PicoError { fn from(value: embassy_net::tcp::Error) -> Self { Self::TcpError(value) } } impl From for PicoError { fn from(_value: snow::Error) -> Self { Self::NoiseProtoError } }