From 38b4ce2c2403a9b6896523fd2bd83daab1621657 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 16 Apr 2022 11:49:17 +0100 Subject: [PATCH] js: Notice errors during start() and display them Otherwise if the game is buggy, you can get a fundamentally broken and unresponsive UI, and no indication that this isn't your fault. Signed-off-by: Ian Jackson --- templates/script.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/templates/script.ts b/templates/script.ts index 024c42a4..81bbfcd7 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -209,8 +209,11 @@ function json_report_error(error_for_json: Object) { } function string_report_error(error_message: String) { + string_report_error_raw('Error (reloading may help?): ' + error_message) +} +function string_report_error_raw(error_message: String) { let errornode = document.getElementById('error')!; - errornode.textContent += '\nError (reloading may help?):' + error_message; + errornode.textContent += '\n' + error_message; console.error("ERROR reported via log", error_message); // todo want to fix this for at least basic game reconfigs, auto-reload? } @@ -2241,7 +2244,12 @@ function loaded(xhr: XMLHttpRequest){ wasm_promise.then((got_wasm) => { wasm = got_wasm; body.outerHTML = xhr.response; - startup(); + try { + startup(); + } catch (exc) { + let s = exc.toString(); + string_report_error_raw('Exception on load, unrecoverable: ' + s); + } }); } -- 2.30.2