Fix panic dialogue when handling a message (#573)

* Fix panic dialogue when handling a message

* Fix indents for github reporting

* More whitespace improvements
This commit is contained in:
0HyperCube 2022-04-02 21:42:10 +01:00 committed by Keavon Chambers
parent a9ce7b3f51
commit 1455ac3dce
3 changed files with 12 additions and 11 deletions

View file

@ -52,7 +52,7 @@ export function initErrorHandling(editor: EditorState, dialogState: DialogState)
function githubUrl(panicDetails: string): string { function githubUrl(panicDetails: string): string {
const url = new URL("https://github.com/GraphiteEditor/Graphite/issues/new"); const url = new URL("https://github.com/GraphiteEditor/Graphite/issues/new");
const body = stripIndents` let body = stripIndents`
**Describe the Crash** **Describe the Crash**
Explain clearly what you were doing when the crash occurred. Explain clearly what you were doing when the crash occurred.
@ -72,11 +72,11 @@ function githubUrl(panicDetails: string): string {
**Stack Trace** **Stack Trace**
Copied from the crash dialog in the Graphite Editor: Copied from the crash dialog in the Graphite Editor:
`;
\`\`\` body += "\n\n```\n";
${panicDetails} body += panicDetails.trimEnd();
\`\`\` body += "\n```";
`;
const fields = { const fields = {
title: "[Crash Report] ", title: "[Crash Report] ",

View file

@ -4,7 +4,7 @@
use crate::helpers::Error; use crate::helpers::Error;
use crate::type_translators::{translate_blend_mode, translate_key, translate_tool_type}; use crate::type_translators::{translate_blend_mode, translate_key, translate_tool_type};
use crate::{EDITOR_HAS_CRASHED, EDITOR_INSTANCES}; use crate::{EDITOR_HAS_CRASHED, EDITOR_INSTANCES, JS_EDITOR_HANDLES};
use editor::consts::{FILE_SAVE_SUFFIX, GRAPHITE_DOCUMENT_VERSION}; use editor::consts::{FILE_SAVE_SUFFIX, GRAPHITE_DOCUMENT_VERSION};
use editor::input::input_preprocessor::ModifierKeys; use editor::input::input_preprocessor::ModifierKeys;
@ -40,7 +40,8 @@ impl JsEditorHandle {
let editor_id = generate_uuid(); let editor_id = generate_uuid();
let editor = Editor::new(); let editor = Editor::new();
let editor_handle = JsEditorHandle { editor_id, handle_response }; let editor_handle = JsEditorHandle { editor_id, handle_response };
EDITOR_INSTANCES.with(|instances| instances.borrow_mut().insert(editor_id, (editor, editor_handle.clone()))); EDITOR_INSTANCES.with(|instances| instances.borrow_mut().insert(editor_id, editor));
JS_EDITOR_HANDLES.with(|instances| instances.borrow_mut().insert(editor_id, editor_handle.clone()));
editor_handle editor_handle
} }
@ -56,7 +57,6 @@ impl JsEditorHandle {
.borrow_mut() .borrow_mut()
.get_mut(&self.editor_id) .get_mut(&self.editor_id)
.expect("EDITOR_INSTANCES does not contain the current editor_id") .expect("EDITOR_INSTANCES does not contain the current editor_id")
.0
.handle_message(message.into()) .handle_message(message.into())
}); });
for response in responses.into_iter() { for response in responses.into_iter() {

View file

@ -16,7 +16,8 @@ use wasm_bindgen::prelude::*;
pub static EDITOR_HAS_CRASHED: AtomicBool = AtomicBool::new(false); pub static EDITOR_HAS_CRASHED: AtomicBool = AtomicBool::new(false);
pub static LOGGER: WasmLog = WasmLog; pub static LOGGER: WasmLog = WasmLog;
thread_local! { thread_local! {
pub static EDITOR_INSTANCES: RefCell<HashMap<u64, (editor::Editor, api::JsEditorHandle)>> = RefCell::new(HashMap::new()); pub static EDITOR_INSTANCES: RefCell<HashMap<u64, editor::Editor>> = RefCell::new(HashMap::new());
pub static JS_EDITOR_HANDLES: RefCell<HashMap<u64, api::JsEditorHandle>> = RefCell::new(HashMap::new());
} }
// Initialize the backend // Initialize the backend
@ -34,9 +35,9 @@ fn panic_hook(info: &panic::PanicInfo) {
let title = "The editor crashed — sorry about that".to_string(); let title = "The editor crashed — sorry about that".to_string();
let description = "An internal error occurred. Reload the editor to continue. Please report this by filing an issue on GitHub.".to_string(); let description = "An internal error occurred. Reload the editor to continue. Please report this by filing an issue on GitHub.".to_string();
log::error!("{}", info); log::error!("{}", info);
EDITOR_INSTANCES.with(|instances| { JS_EDITOR_HANDLES.with(|instances| {
instances.borrow_mut().values_mut().for_each(|instance| { instances.borrow_mut().values_mut().for_each(|instance| {
instance.1.handle_response_rust_proxy(FrontendMessage::DisplayDialogPanic { instance.handle_response_rust_proxy(FrontendMessage::DisplayDialogPanic {
panic_info: panic_info.clone(), panic_info: panic_info.clone(),
title: title.clone(), title: title.clone(),
description: description.clone(), description: description.clone(),