From: Ian Jackson Date: Sat, 16 Apr 2022 10:49:17 +0000 (+0100) Subject: js: Notice errors during start() and display them X-Git-Tag: otter-1.1.0~535 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=38b4ce2c2403a9b6896523fd2bd83daab1621657;p=otter.git 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 --- 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); + } }); }