Skip to content

Commit aa21711

Browse files
committed
Remove JavaError::FatalError
1 parent fb2170f commit aa21711

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

jvm/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
use alloc::{
22
boxed::Box,
33
fmt::{self, Display, Formatter},
4-
string::String,
54
};
65

76
use crate::ClassInstance;
87

98
#[derive(Debug)]
109
pub enum JavaError {
1110
JavaException(Box<dyn ClassInstance>),
12-
FatalError(String),
1311
}
1412

1513
impl Display for JavaError {
1614
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1715
match self {
1816
JavaError::JavaException(e) => write!(f, "Java exception: {e:?}"),
19-
JavaError::FatalError(e) => write!(f, "Fatal error: {e}"),
2017
}
2118
}
2219
}

jvm_rust/src/interpreter.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl Interpreter {
5858
return Err(JavaError::JavaException(e));
5959
}
6060
}
61-
Err(e) => return Err(e),
6261
}
6362
}
6463

@@ -680,7 +679,9 @@ impl Interpreter {
680679
let value2: i32 = stack_frame.operand_stack.pop().unwrap().into();
681680
let value1: i32 = stack_frame.operand_stack.pop().unwrap().into();
682681

683-
stack_frame.operand_stack.push(JavaValue::Int(((value1 as u32) >> ((value2 as u32) & 0x1f)) as _));
682+
stack_frame
683+
.operand_stack
684+
.push(JavaValue::Int(((value1 as u32) >> ((value2 as u32) & 0x1f)) as _));
684685
}
685686
Opcode::Ixor => {
686687
let value2: i32 = stack_frame.operand_stack.pop().unwrap().into();
@@ -786,7 +787,9 @@ impl Interpreter {
786787
let value2: i32 = stack_frame.operand_stack.pop().unwrap().into();
787788
let value1: i64 = stack_frame.operand_stack.pop().unwrap().into();
788789

789-
stack_frame.operand_stack.push(JavaValue::Long(((value1 as u64) >> ((value2 as u64) & 0x3f)) as _));
790+
stack_frame
791+
.operand_stack
792+
.push(JavaValue::Long(((value1 as u64) >> ((value2 as u64) & 0x3f)) as _));
790793
}
791794
Opcode::Lxor => {
792795
let value2: i64 = stack_frame.operand_stack.pop().unwrap().into();

src/lib.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,24 @@ where
2323

2424
let result = invoke_entrypoint(&jvm, &start_type, args).await;
2525

26-
if let Err(x) = result {
27-
Err(match x {
28-
JavaError::JavaException(x) => {
29-
let string_writer = jvm.new_class("java/io/StringWriter", "()V", ()).await.unwrap();
30-
let print_writer = jvm
31-
.new_class("java/io/PrintWriter", "(Ljava/io/Writer;)V", (string_writer.clone(),))
32-
.await
33-
.unwrap();
34-
35-
let _: () = jvm
36-
.invoke_virtual(&x, "printStackTrace", "(Ljava/io/PrintWriter;)V", (print_writer,))
37-
.await
38-
.unwrap();
39-
40-
let trace = jvm.invoke_virtual(&string_writer, "toString", "()Ljava/lang/String;", []).await.unwrap();
41-
42-
anyhow::anyhow!("Java Exception:\n{}", JavaLangString::to_rust_string(&jvm, &trace).await.unwrap())
43-
}
44-
JavaError::FatalError(x) => anyhow::anyhow!("Fatal error: {x}"),
45-
})
26+
if let Err(JavaError::JavaException(x)) = result {
27+
let string_writer = jvm.new_class("java/io/StringWriter", "()V", ()).await.unwrap();
28+
let print_writer = jvm
29+
.new_class("java/io/PrintWriter", "(Ljava/io/Writer;)V", (string_writer.clone(),))
30+
.await
31+
.unwrap();
32+
33+
let _: () = jvm
34+
.invoke_virtual(&x, "printStackTrace", "(Ljava/io/PrintWriter;)V", (print_writer,))
35+
.await
36+
.unwrap();
37+
38+
let trace = jvm.invoke_virtual(&string_writer, "toString", "()Ljava/lang/String;", []).await.unwrap();
39+
40+
Err(anyhow::anyhow!(
41+
"Java Exception:\n{}",
42+
JavaLangString::to_rust_string(&jvm, &trace).await.unwrap()
43+
))
4644
} else {
4745
Ok(result?)
4846
}

0 commit comments

Comments
 (0)