1#[cfg(feature = "backtrace")]
4use std::backtrace::Backtrace;
5use std::borrow::Cow;
6use std::{io, string};
7use thiserror::Error;
8
9pub type Result<T> = std::result::Result<T, Error>;
11
12#[derive(Error, Debug)]
19#[error("{kind}")]
20pub struct Error {
21 kind: ErrorKind,
22
23 #[cfg(feature = "backtrace")]
24 backtrace: Backtrace,
25}
26
27impl From<ErrorKind> for Error {
28 #[cfg(feature = "backtrace")]
29 fn from(kind: ErrorKind) -> Self {
30 Error {
31 kind,
32 backtrace: Backtrace::capture(),
33 }
34 }
35
36 #[cfg(not(feature = "backtrace"))]
37 fn from(kind: ErrorKind) -> Self {
38 Error { kind }
39 }
40}
41
42impl From<std::io::Error> for Error {
43 fn from(err: std::io::Error) -> Self {
44 ErrorKind::from(err).into()
45 }
46}
47
48impl From<std::string::FromUtf16Error> for Error {
49 fn from(err: std::string::FromUtf16Error) -> Self {
50 ErrorKind::from(err).into()
51 }
52}
53
54impl From<widestring::MissingNulError<u16>> for Error {
55 fn from(err: widestring::MissingNulError<u16>) -> Self {
56 ErrorKind::from(err).into()
57 }
58}
59
60impl From<uuid::Error> for Error {
61 fn from(err: uuid::Error) -> Self {
62 ErrorKind::from(err).into()
63 }
64}
65
66#[allow(missing_docs)]
68#[derive(Error, Debug)]
69pub enum ErrorKind {
70 #[error("Unexpected end of file")]
72 UnexpectedEof,
73
74 #[error("Not a table of contents file: {file}")]
76 NotATocFile { file: String },
77
78 #[error("Not a section file: {file}")]
80 NotASectionFile { file: String },
81
82 #[error("Table of contents file is missing in dir {dir}")]
84 TocFileMissing { dir: String },
85
86 #[error("Malformed data: {0}")]
88 MalformedData(Cow<'static, str>),
89
90 #[error("Malformed OneNote data: {0}")]
92 MalformedOneNoteData(Cow<'static, str>),
93
94 #[error("Malformed OneNote file data: {0}")]
96 MalformedOneNoteFileData(Cow<'static, str>),
97
98 #[error("Malformed OneStore data: {0}")]
100 MalformedOneStoreData(Cow<'static, str>),
101
102 #[error("Malformed FSSHTTPB data: {0}")]
104 MalformedFssHttpBData(Cow<'static, str>),
105
106 #[error("Invalid UUID: {err}")]
108 InvalidUuid {
109 #[from]
110 err: uuid::Error,
111 },
112
113 #[error("I/O failure: {err}")]
115 IO {
116 #[from]
117 err: io::Error,
118 },
119
120 #[error("Malformed UTF-16 string: {err}")]
122 Utf16Error {
123 #[from]
124 err: string::FromUtf16Error,
125 },
126
127 #[error("UTF-16 string is missing null terminator: {err}")]
129 Utf16MissingNull {
130 #[from]
131 err: widestring::MissingNulError<u16>,
132 },
133}