1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use std::io;
use std::str;
use std::ffi;
#[cfg(feature = "with_dwarf")]
use gimli;
#[cfg(feature = "with_objects")]
use goblin;
#[cfg(feature = "with_objects")]
use scroll;
#[cfg(feature = "with_sourcemaps")]
use sourcemap;
error_chain! {
errors {
Panic(message: String) {
description("panic")
display("panic: {}", message)
}
BadSymbol(message: String) {
description("bad symbol")
display("bad symbol: {}", &message)
}
Internal(message: &'static str) {
description("internal error")
display("internal error: {}", message)
}
Parse(message: &'static str) {
description("parse error")
display("parse error: {}", message)
}
NotFound(message: &'static str) {
description("not found")
display("not found: {}", message)
}
Format(message: &'static str) {
description("format error")
display("format error: {}", message)
}
UnsupportedObjectFile {
description("unsupported object file")
}
MalformedObjectFile(message: String) {
description("malformed object file")
display("malformed object file: {}", &message)
}
BadCacheFile(msg: &'static str) {
description("bad cache file")
display("bad cache file: {}", msg)
}
MissingSection(section: &'static str) {
description("missing object section")
display("missing object section '{}'", section)
}
BadDwarfData(message: &'static str) {
description("bad dwarf data")
display("bad dwarf data: {}", message)
}
BadBreakpadSym(msg: &'static str) {
description("bad breakpad sym")
display("bad breakpad sym: {}", msg)
}
MissingDebugInfo(message: &'static str) {
description("missing debug info")
display("missing debug info: {}", message)
}
BadSymbolTable(message: &'static str) {
description("bad symbol table")
display("bad symbol table: {}", message)
}
BadJson(msg: String) {
description("bad json")
display("bad json: {}", &msg)
}
BadSourcemap(msg: String) {
description("bad sourcemap")
display("bad sourcemap: {}", &msg)
}
Stackwalk(message: String) {
description("stackwalking error")
display("stackwalking error: {}", message)
}
Resolver(message: String) {
description("resolver error")
display("resolver error: {}", message)
}
CannotFlattenSourcemap(msg: String) {
description("cannot flatten sourcemap")
display("cannot flatten sourcemap: {}", &msg)
}
}
foreign_links {
Io(io::Error);
Utf8Error(str::Utf8Error);
ParseInt(::std::num::ParseIntError);
}
}
#[cfg(feature = "with_dwarf")]
impl From<gimli::Error> for Error {
fn from(err: gimli::Error) -> Error {
use std::mem;
use std::error::Error;
ErrorKind::BadDwarfData(unsafe { mem::transmute(err.description()) }).into()
}
}
#[cfg(feature = "with_objects")]
impl From<goblin::error::Error> for Error {
fn from(err: goblin::error::Error) -> Error {
use goblin::error::Error::*;
match err {
Malformed(s) => ErrorKind::MalformedObjectFile(s).into(),
BadMagic(m) => ErrorKind::MalformedObjectFile(format!("bad magic: {}", m)).into(),
Scroll(err) => Error::from(err),
IO(err) => Error::from(err),
}
}
}
#[cfg(feature = "with_objects")]
impl From<scroll::Error> for Error {
fn from(err: scroll::Error) -> Error {
use scroll::Error::*;
match err {
TooBig { .. } => io::Error::new(
io::ErrorKind::UnexpectedEof,
"Tried to read type that was too large",
).into(),
BadOffset(..) => io::Error::new(io::ErrorKind::InvalidData, "Bad offset").into(),
BadInput { .. } => io::Error::new(io::ErrorKind::InvalidData, "Bad input").into(),
Custom(s) => io::Error::new(io::ErrorKind::Other, s).into(),
IO(err) => Error::from(err),
}
}
}
#[cfg(feature = "with_sourcemaps")]
impl From<sourcemap::Error> for Error {
fn from(err: sourcemap::Error) -> Error {
use sourcemap::Error::*;
match err {
Io(err) => Error::from(err),
Utf8(err) => Error::from(err),
BadJson(err) => Error::from(ErrorKind::BadJson(err.to_string())),
CannotFlatten(msg) => Error::from(ErrorKind::CannotFlattenSourcemap(msg)),
err => Error::from(ErrorKind::BadSourcemap(err.to_string())),
}
}
}
impl From<ffi::NulError> for Error {
fn from(_err: ffi::NulError) -> Error {
ErrorKind::Internal("unexpected null byte in c-string").into()
}
}