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    /// Wraps an error returned by the protobuf parser.
11    ProtobufError(protobuf::Error),
12    /// Indicates that the frame size was invalid.
13    InvalidFrameSize(usize),
14    /// Wraps an error returned by the LZMA decompression.
15    XZError(lzma_rs::error::Error),
16    /// Indicates that the compression method is unknown.
17    CompressionUnknown,
18    /// Indicates that the strokes length is invalid.
19    InvalidStrokesLength(usize, usize),
20    /// Indicates a numeric conversion error.
21    ConversionError,
22    /// Indicates that the decompressed data was not set.
23    DecompressedNotSet,
24    /// Indicates that the decompressed length is invalid.
25    InvalidDecompressedLength(usize, usize),
26    /// Wraps an error that occurred during resizing of handwriting coordinates.
27    ResizeError(std::num::TryFromIntError),
28}
29
30impl Display for HandwritingError {
31    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
32        match self {
33            HandwritingError::ProtobufError(why) => {
34                write!(fmt, "failed to parse handwriting protobuf: {why}")
35            }
36            HandwritingError::InvalidFrameSize(size) => write!(fmt, "expected size 8, got {size}"),
37            HandwritingError::XZError(why) => write!(fmt, "failed to decompress xz: {why}"),
38            HandwritingError::CompressionUnknown => write!(fmt, "compress method unknown"),
39            HandwritingError::InvalidStrokesLength(index, length) => {
40                write!(fmt, "can't access index {index} on array length {length}")
41            }
42            HandwritingError::ConversionError => write!(fmt, "failed to convert num"),
43            HandwritingError::DecompressedNotSet => {
44                write!(fmt, "decompressed length not set on compressed message")
45            }
46            HandwritingError::InvalidDecompressedLength(expected, got) => {
47                write!(fmt, "expected decompressed length of {expected}, got {got}")
48            }
49            HandwritingError::ResizeError(why) => {
50                write!(fmt, "failed to resize handwriting coordinates: {why}")
51            }
52        }
53    }
54}