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