File tree 5 files changed +23
-22
lines changed 5 files changed +23
-22
lines changed Original file line number Diff line number Diff line change 6
6
use jni:: objects:: { GlobalRef , JClass , JObject , JValue } ;
7
7
use jni:: sys:: jint;
8
8
use jni:: { JNIEnv , JavaVM } ;
9
- use libsignal_bridge:: jni_signature;
10
- use std:: any:: Any ;
9
+ use libsignal_bridge:: { describe_panic, jni_signature} ;
11
10
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
12
11
use std:: process:: abort;
13
12
@@ -118,17 +117,6 @@ impl log::Log for JniLogger {
118
117
fn flush ( & self ) { }
119
118
}
120
119
121
- // See https://github.com/rust-lang/rfcs/issues/1389
122
- fn describe_panic ( any : & Box < dyn Any + Send > ) -> String {
123
- if let Some ( msg) = any. downcast_ref :: < & str > ( ) {
124
- msg. to_string ( )
125
- } else if let Some ( msg) = any. downcast_ref :: < String > ( ) {
126
- msg. to_string ( )
127
- } else {
128
- "(break on rust_panic to debug)" . to_string ( )
129
- }
130
- }
131
-
132
120
/// A low-level version of `run_ffi_safe` that just aborts on errors.
133
121
///
134
122
/// This is important for logging failures because we might want to log during the normal
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ use device_transfer::Error as DeviceTransferError;
10
10
use libsignal_protocol:: * ;
11
11
use signal_crypto:: Error as SignalCryptoError ;
12
12
13
+ use crate :: support:: describe_panic;
14
+
13
15
/// The top-level error type (opaquely) returned to C clients when something goes wrong.
14
16
#[ derive( Debug ) ]
15
17
pub enum SignalFfiError {
@@ -39,11 +41,9 @@ impl fmt::Display for SignalFfiError {
39
41
SignalFfiError :: InsufficientOutputSize ( n, h) => {
40
42
write ! ( f, "needed {} elements only {} provided" , n, h)
41
43
}
42
-
43
- SignalFfiError :: UnexpectedPanic ( e) => match e. downcast_ref :: < & ' static str > ( ) {
44
- Some ( s) => write ! ( f, "unexpected panic: {}" , s) ,
45
- None => write ! ( f, "unknown unexpected panic" ) ,
46
- } ,
44
+ SignalFfiError :: UnexpectedPanic ( e) => {
45
+ write ! ( f, "unexpected panic: {}" , describe_panic( e) )
46
+ }
47
47
}
48
48
}
49
49
}
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ use hsm_enclave::Error as HsmEnclaveError;
12
12
use libsignal_protocol:: * ;
13
13
use signal_crypto:: Error as SignalCryptoError ;
14
14
15
+ use crate :: support:: describe_panic;
16
+
15
17
use super :: * ;
16
18
17
19
/// The top-level error type for when something goes wrong.
@@ -47,10 +49,9 @@ impl fmt::Display for SignalJniError {
47
49
SignalJniError :: HsmEnclave ( e) => {
48
50
write ! ( f, "{}" , e)
49
51
}
50
- SignalJniError :: UnexpectedPanic ( e) => match e. downcast_ref :: < & ' static str > ( ) {
51
- Some ( s) => write ! ( f, "unexpected panic: {}" , s) ,
52
- None => write ! ( f, "unknown unexpected panic" ) ,
53
- } ,
52
+ SignalJniError :: UnexpectedPanic ( e) => {
53
+ write ! ( f, "unexpected panic: {}" , describe_panic( e) )
54
+ }
54
55
}
55
56
}
56
57
}
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ pub mod node;
23
23
24
24
#[ macro_use]
25
25
mod support;
26
+ pub use support:: describe_panic;
26
27
27
28
pub mod crypto;
28
29
pub mod protocol;
Original file line number Diff line number Diff line change @@ -8,6 +8,17 @@ pub(crate) use paste::paste;
8
8
mod transform_helper;
9
9
pub ( crate ) use transform_helper:: * ;
10
10
11
+ // See https://github.com/rust-lang/rfcs/issues/1389
12
+ pub fn describe_panic ( any : & Box < dyn std:: any:: Any + Send > ) -> String {
13
+ if let Some ( msg) = any. downcast_ref :: < & str > ( ) {
14
+ msg. to_string ( )
15
+ } else if let Some ( msg) = any. downcast_ref :: < String > ( ) {
16
+ msg. to_string ( )
17
+ } else {
18
+ "(break on rust_panic to debug)" . to_string ( )
19
+ }
20
+ }
21
+
11
22
/// Exposes a Rust type to each of the bridges as a boxed value.
12
23
///
13
24
/// Full form:
You can’t perform that action at this time.
0 commit comments