ole/
error.rs

1//             DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2//                    Version 2, December 2004
3//
4// Copyright (C) 2018 Thomas Bailleux <thomas@bailleux.me>
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13//  0. You just DO WHAT THE FUCK YOU WANT TO.
14//
15// Author: zadig <thomas chr(0x40) bailleux.me>
16
17use std;
18
19/// Errors related to the process of parsing.
20#[derive(Debug)]
21pub enum Error {
22  /// This happens when filesize is null, or to big to fit into an usize.
23  BadFileSize,
24
25  /// Classic std::io::Error.
26  IOError(std::io::Error),
27
28  /// Something is not implemented yet ?
29  NotImplementedYet,
30
31  /// This is not a valid OLE file.
32  InvalidOLEFile,
33
34  /// Something has a bad size.
35  BadSizeValue(&'static str),
36
37  /// MSAT is empty.
38  EmptyMasterSectorAllocationTable,
39
40  /// Malformed SAT.
41  NotSectorUsedBySAT,
42
43  /// Unknown node type.
44  NodeTypeUnknown,
45
46  /// Root storage has a bad size.
47  BadRootStorageSize,
48
49  /// User query an empty entry
50  EmptyEntry,
51}
52
53impl std::error::Error for Error {
54  fn description(&self) -> &str {
55    match *self {
56      Error::BadFileSize => "Filesize is null or too big.",
57      Error::IOError(ref e) => e.description(),
58      Error::NotImplementedYet => "Method not implemented yet",
59      Error::InvalidOLEFile => "Invalid OLE File",
60      Error::BadSizeValue(ref e) => e,
61      Error::EmptyMasterSectorAllocationTable => "MSAT is empty",
62      Error::NotSectorUsedBySAT => "Sector is not a sector used by the SAT.",
63      Error::NodeTypeUnknown => "Unknown node type",
64      Error::BadRootStorageSize => "Bad RootStorage size",
65      Error::EmptyEntry => "Empty entry"
66    }
67  }
68
69  fn cause(&self) -> Option<&std::error::Error> {
70    match *self {
71      Error::IOError(ref e) => Some(e),
72      _ => None
73    }
74  }
75}
76
77impl std::fmt::Display for Error {
78  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
79    use std::error::Error;
80    write!(f, "{}", self.description())
81  }
82}