imessage_database/error/
handwriting.rs1use std::fmt::{Display, Formatter, Result};
6
7#[derive(Debug)]
9pub enum HandwritingError {
10 ProtobufError(protobuf::Error),
12 InvalidFrameSize(usize),
14 XZError(lzma_rs::error::Error),
16 CompressionUnknown,
18 InvalidStrokesLength(usize, usize),
20 ConversionError,
22 DecompressedNotSet,
24 InvalidDecompressedLength(usize, usize),
26 ResizeError(std::num::TryFromIntError),
28}
29
30impl std::error::Error for HandwritingError {
31 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
32 match self {
33 HandwritingError::ProtobufError(e) => Some(e),
34 HandwritingError::XZError(e) => Some(e),
35 HandwritingError::ResizeError(e) => Some(e),
36 _ => None,
37 }
38 }
39}
40
41impl Display for HandwritingError {
42 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
43 match self {
44 HandwritingError::ProtobufError(why) => {
45 write!(fmt, "failed to parse handwriting protobuf: {why}")
46 }
47 HandwritingError::InvalidFrameSize(size) => write!(fmt, "expected size 8, got {size}"),
48 HandwritingError::XZError(why) => write!(fmt, "failed to decompress xz: {why}"),
49 HandwritingError::CompressionUnknown => write!(fmt, "compress method unknown"),
50 HandwritingError::InvalidStrokesLength(index, length) => {
51 write!(fmt, "can't access index {index} on array length {length}")
52 }
53 HandwritingError::ConversionError => write!(fmt, "failed to convert num"),
54 HandwritingError::DecompressedNotSet => {
55 write!(fmt, "decompressed length not set on compressed message")
56 }
57 HandwritingError::InvalidDecompressedLength(expected, got) => {
58 write!(fmt, "expected decompressed length of {expected}, got {got}")
59 }
60 HandwritingError::ResizeError(why) => {
61 write!(fmt, "failed to resize handwriting coordinates: {why}")
62 }
63 }
64 }
65}