js_deobfuscator/core/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
11pub enum DeobError {
12 #[error("parse error: {0}")]
14 Parse(String),
15
16 #[error("transform error: {0}")]
18 Transform(String),
19
20 #[error("pass error in {pass}: {message}")]
22 Pass {
23 pass: &'static str,
25 message: String,
27 },
28
29 #[error("configuration error: {0}")]
31 Config(String),
32
33 #[error("max iterations reached without convergence")]
35 MaxIterations,
36}
37
38impl DeobError {
39 pub fn parse(message: impl Into<String>) -> Self {
41 Self::Parse(message.into())
42 }
43
44 pub fn transform(message: impl Into<String>) -> Self {
46 Self::Transform(message.into())
47 }
48
49 pub fn pass(pass: &'static str, message: impl Into<String>) -> Self {
51 Self::Pass {
52 pass,
53 message: message.into(),
54 }
55 }
56
57 pub fn config(message: impl Into<String>) -> Self {
59 Self::Config(message.into())
60 }
61}
62
63#[derive(Debug, Clone)]
71pub struct PassError {
72 pub pass: &'static str,
74
75 pub message: String,
77
78 pub recoverable: bool,
80}
81
82impl PassError {
83 pub fn new(pass: &'static str, message: impl Into<String>) -> Self {
85 Self {
86 pass,
87 message: message.into(),
88 recoverable: true,
89 }
90 }
91
92 pub fn fatal(pass: &'static str, message: impl Into<String>) -> Self {
94 Self {
95 pass,
96 message: message.into(),
97 recoverable: false,
98 }
99 }
100}
101
102impl std::fmt::Display for PassError {
103 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
104 write!(f, "[{}] {}", self.pass, self.message)
105 }
106}