1use std::ops::Deref;
2use bincode::ErrorKind;
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11
12 #[error("Error converting IR to string")]
16 Format(#[from] std::fmt::Error),
17
18 #[error("Unexpected end of bytes. Deserialiser expected more bytes in the decompress slice")]
22 UnexpectedEndOfBytes,
23
24 #[error("Could not deserialize invalid unicode scalar value")]
26 InvalidUnicodeChar,
27
28 #[error("Unexpected bincode error")]
30 OtherBincode(bincode::Error),
31}
32
33impl From<bincode::Error> for Error {
34 fn from(value: bincode::Error) -> Self {
35 match value.deref() {
36 ErrorKind::InvalidCharEncoding => {
37 Error::InvalidUnicodeChar
38 }
39 ErrorKind::SizeLimit => {
40 Error::UnexpectedEndOfBytes
41 }
42 ErrorKind::Io(e) => {
43 match e.kind() {
44 std::io::ErrorKind::UnexpectedEof => {
45 Error::UnexpectedEndOfBytes
46 }
47 _ => {
48 Error::OtherBincode(value)
49 }
50 }
51 }
52 _ => {
53 Error::OtherBincode(value)
54 }
55 }
56 }
57}