forked from argotorg/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.rs
More file actions
82 lines (69 loc) · 2.16 KB
/
Copy patherrors.rs
File metadata and controls
82 lines (69 loc) · 2.16 KB
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
//! Errors returned by the compilers and ABI builder.
pub use fe_analyzer::errors::AnalyzerError;
use fe_common::diagnostics::Diagnostic;
use once_cell::sync::Lazy;
use std::borrow::Cow;
use std::panic;
const BUG_REPORT_URL: &str = "https://github.com/ethereum/fe/issues/new";
static DEFAULT_PANIC_HOOK: Lazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
Lazy::new(|| {
let hook = panic::take_hook();
panic::set_hook(Box::new(|info| report_ice(info)));
hook
});
pub fn install_compiler_panic_hook() {
Lazy::force(&DEFAULT_PANIC_HOOK);
}
/// Errors can either be an object or static reference.
#[derive(Debug)]
pub enum ErrorKind {
Str(Cow<'static, str>),
Analyzer(AnalyzerError),
Parser(Vec<Diagnostic>),
}
/// List of errors encountered during compilation.
#[derive(Debug)]
pub struct CompileError {
pub errors: Vec<ErrorKind>,
}
impl Default for CompileError {
fn default() -> Self {
Self::new()
}
}
impl CompileError {
pub fn new() -> Self {
Self { errors: Vec::new() }
}
/// Create a single error with a static string.
pub fn static_str(val: &'static str) -> Self {
Self {
errors: vec![ErrorKind::Str(val.into())],
}
}
/// Create a single error with a string object.
pub fn str(val: &str) -> Self {
Self {
errors: vec![ErrorKind::Str(val.to_string().into())],
}
}
}
impl<'a> From<serde_json::error::Error> for CompileError {
fn from(_: serde_json::error::Error) -> Self {
CompileError::static_str("JSON serialization error")
}
}
impl<'a> From<ethabi::Error> for CompileError {
fn from(e: ethabi::Error) -> Self {
CompileError::str(&format!("ethabi error: {}", e))
}
}
fn report_ice(info: &panic::PanicInfo) {
(*DEFAULT_PANIC_HOOK)(info);
eprintln!();
eprintln!("You've hit an internal compiler error. This is a bug in the Fe compiler.");
eprintln!("Fe is still under heavy development, and isn't yet ready for production use.");
eprintln!();
eprintln!("If you would, please report this bug at the following URL:");
eprintln!(" {}", BUG_REPORT_URL);
}