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 InvalidDimensions(u16, u16),
16 XZError(lzma_rs::error::Error),
18 CompressionUnknown,
20 InvalidStrokesLength(usize, usize),
22 EmptyStroke,
24 ConversionError,
26 DecompressedNotSet,
28 InvalidDecompressedLength(usize, usize),
30 ResizeError(std::num::TryFromIntError),
32}
33
34impl std::error::Error for HandwritingError {
35 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
36 match self {
37 HandwritingError::ProtobufError(e) => Some(e),
38 HandwritingError::XZError(e) => Some(e),
39 HandwritingError::ResizeError(e) => Some(e),
40 _ => None,
41 }
42 }
43}
44
45impl Display for HandwritingError {
46 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
47 match self {
48 HandwritingError::ProtobufError(why) => {
49 write!(fmt, "failed to parse handwriting protobuf: {why}")
50 }
51 HandwritingError::InvalidFrameSize(size) => write!(fmt, "expected size 8, got {size}"),
52 HandwritingError::InvalidDimensions(width, height) => {
53 write!(fmt, "frame dimensions {width}x{height} are out of range")
54 }
55 HandwritingError::XZError(why) => write!(fmt, "failed to decompress xz: {why}"),
56 HandwritingError::CompressionUnknown => write!(fmt, "compress method unknown"),
57 HandwritingError::InvalidStrokesLength(index, length) => {
58 write!(fmt, "can't access index {index} on array length {length}")
59 }
60 HandwritingError::EmptyStroke => write!(fmt, "stroke contains zero points"),
61 HandwritingError::ConversionError => write!(fmt, "failed to convert num"),
62 HandwritingError::DecompressedNotSet => {
63 write!(fmt, "decompressed length not set on compressed message")
64 }
65 HandwritingError::InvalidDecompressedLength(expected, got) => {
66 write!(fmt, "expected decompressed length of {expected}, got {got}")
67 }
68 HandwritingError::ResizeError(why) => {
69 write!(fmt, "failed to resize handwriting coordinates: {why}")
70 }
71 }
72 }
73}