forked from swc-project/swc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.rs
50 lines (39 loc) · 1.54 KB
/
error.rs
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
use failure::Fail;
use once_cell::sync::Lazy;
use regex;
use serde_json;
use sourcemap;
use std::{io, string::FromUtf8Error};
#[derive(Debug, Fail)]
pub enum Error {
#[fail(display = "failed to read config file: {}", err)]
FailedToReadConfigFile { err: io::Error },
#[fail(display = "failed to parse config file: {}", err)]
FailedToParseConfigFile { err: serde_json::error::Error },
#[fail(display = "failed to parse module")]
FailedToParseModule {},
#[fail(display = "failed to read module: {}", err)]
FailedToReadModule { err: io::Error },
#[fail(display = "failed to emit module: {}", err)]
FailedToEmitModule { err: io::Error },
#[fail(display = "failed to write sourcemap: {}", err)]
FailedToWriteSourceMap { err: sourcemap::Error },
#[fail(display = "sourcemap is not utf8: {}", err)]
SourceMapNotUtf8 { err: FromUtf8Error },
#[fail(display = "invalid regexp: {}: {}", regex, err)]
InvalidRegex { regex: String, err: regex::Error },
/* #[fail(display = "generated code is not utf8: {}", err)]
* GeneratedCodeNotUtf8 { err: FromUtf8Error }, */
/// This means `test` field in .swcrc file did not matched the compiling
/// file.
#[fail(display = "unmatched")]
Unmatched,
}
/// Returns true if `SWC_DEBUG` environment is set to `1` or `true`.
pub(crate) fn debug() -> bool {
static DEBUG: Lazy<bool> = Lazy::new(|| match ::std::env::var("SWC_DEBUG") {
Ok(ref v) if v == "1" || v.eq_ignore_ascii_case("true") => true,
_ => false,
});
*DEBUG
}