imessage_database/error/
handwriting.rs

1/*!
2 Errors that can happen when parsing `handwriting` data.
3*/
4
5use std::fmt::{Display, Formatter, Result};
6
7/// Errors that can happen when parsing `handwriting` data
8#[derive(Debug)]
9pub enum HandwritingError {
10    ProtobufError(protobuf::Error),
11    InvalidFrameSize(usize),
12    XZError(lzma_rs::error::Error),
13    CompressionUnknown,
14    InvalidStrokesLength(usize, usize),
15    ConversionError,
16    DecompressedNotSet,
17    InvalidDecompressedLength(usize, usize),
18    ResizeError(std::num::TryFromIntError),
19}
20
21impl Display for HandwritingError {
22    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
23        match self {
24            HandwritingError::ProtobufError(why) => {
25                write!(fmt, "failed to parse handwriting protobuf: {why}")
26            }
27            HandwritingError::InvalidFrameSize(size) => write!(fmt, "expected size 8, got {size}"),
28            HandwritingError::XZError(why) => write!(fmt, "failed to decompress xz: {why}"),
29            HandwritingError::CompressionUnknown => write!(fmt, "compress method unknown"),
30            HandwritingError::InvalidStrokesLength(index, length) => {
31                write!(fmt, "can't access index {index} on array length {length}")
32            }
33            HandwritingError::ConversionError => write!(fmt, "failed to convert num"),
34            HandwritingError::DecompressedNotSet => {
35                write!(fmt, "decompressed length not set on compressed message")
36            }
37            HandwritingError::InvalidDecompressedLength(expected, got) => {
38                write!(fmt, "expected decompressed length of {expected}, got {got}")
39            }
40            HandwritingError::ResizeError(why) => {
41                write!(fmt, "failed to resize handwriting coordinates: {why}")
42            }
43        }
44    }
45}