1use std::str::Utf8Error;
2
3use thiserror::Error;
4
5use crate::id::{ENCODED_LENGTH, PREFIX_LENGTH, XID_ENCODED_LENGTH};
6
7#[derive(Clone, Debug, Error, PartialEq, Eq)]
8pub enum DecodeError {
9 #[error("Failed to retrieve the prefix from the provided encoded PXID {0}")]
12 MissingPrefix(String),
13
14 #[error("String cannot be decoded into a PXID instance. {0} length is not valid. Expected length {ENCODED_LENGTH}, but received {1}")]
17 InvalidLength(String, usize),
18
19 #[error("String cannot be decoded into a PXID instance. {0} length is not valid. Expected length {PREFIX_LENGTH}, but received {1}")]
22 InvalidPrefixLength(String, usize),
23
24 #[error("String cannot be decoded into a PXID instance. {0} length is not valid. Found invalid char {1}.")]
27 InvalidChar(String, char),
28
29 #[error("Invalid UTF-8 character encountered")]
31 InvalidUtf8(Utf8Error),
32
33 #[error("String cannot be decoded into a PXID instance. {0} XID length is not valid. Expected length {XID_ENCODED_LENGTH}, but received {1}")]
36 InvalidXidLength(String, usize),
37}
38
39#[derive(Clone, Debug, Error, PartialEq, Eq)]
40pub enum Error {
41 #[error("Failed to decode into a XID. {0}")]
43 Decode(DecodeError),
44
45 #[error("Failed to retrieve Machine ID. {0}")]
47 MachineID(String),
48
49 #[error("Provided prefix: {0} is too long. Max allowed characters are 4.")]
51 PrefixExceedsMaxLength(String),
52}