File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ pub enum EditorError {
20
20
#[ error( "A rollback was initiated but no transaction was in progress" ) ]
21
21
NoTransactionInProgress ,
22
22
23
+ #[ error( "Graphite panicked:\n {0}" ) ]
24
+ Panic ( String ) ,
25
+
23
26
#[ error( "{0}" ) ]
24
27
Misc ( String ) ,
25
28
}
Original file line number Diff line number Diff line change
1
+ use std:: sync:: atomic:: AtomicBool ;
2
+
1
3
use crate :: shims:: Error ;
2
4
use crate :: wrappers:: { translate_key, translate_tool, Color } ;
3
5
use editor:: input:: input_preprocessor:: ModifierKeys ;
@@ -9,14 +11,33 @@ use editor::LayerId;
9
11
use graphene:: layers:: BlendMode ;
10
12
use wasm_bindgen:: prelude:: * ;
11
13
14
+ static EDITOR_HAS_CRASHED : AtomicBool = AtomicBool :: new ( false ) ;
15
+
12
16
fn convert_error ( err : editor:: EditorError ) -> JsValue {
13
17
Error :: new ( & err. to_string ( ) ) . into ( )
14
18
}
15
19
16
20
fn dispatch < T : Into < Message > > ( message : T ) -> Result < ( ) , JsValue > {
17
- let result = crate :: EDITOR_STATE . with ( |state| state. borrow_mut ( ) . handle_message ( message. into ( ) ) ) ;
18
- if let Ok ( messages) = result {
19
- crate :: handle_responses ( messages) ;
21
+ if EDITOR_HAS_CRASHED . load ( std:: sync:: atomic:: Ordering :: SeqCst ) {
22
+ return Ok ( ( ) ) ;
23
+ }
24
+
25
+ let result = crate :: EDITOR_STATE
26
+ . with ( |state| state. try_borrow_mut ( ) . ok ( ) . map ( |mut state| state. handle_message ( message. into ( ) ) ) )
27
+ . unwrap_or_else ( || {
28
+ Err ( EditorError :: Panic ( String :: from (
29
+ "An internal error occurred. Reload the site to continue.\n See the browser's console for details and please report this by filing an issue on GitHub." ,
30
+ ) ) )
31
+ } ) ;
32
+ match result {
33
+ Ok ( messages) => {
34
+ crate :: handle_responses ( messages) ;
35
+ }
36
+ Err ( error) => {
37
+ EDITOR_HAS_CRASHED . store ( true , std:: sync:: atomic:: Ordering :: SeqCst ) ;
38
+
39
+ crate :: handle_response ( FrontendMessage :: DisplayError { description : error. to_string ( ) } ) ;
40
+ }
20
41
}
21
42
Ok ( ( ) )
22
43
}
You can’t perform that action at this time.
0 commit comments