chiark / gitweb /
js: Notice errors during start() and display them
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Apr 2022 10:49:17 +0000 (11:49 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Apr 2022 11:51:17 +0000 (12:51 +0100)
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 <ijackson@chiark.greenend.org.uk>
templates/script.ts

index 024c42a46dbe4071e791e98e78dddd95efbce1a6..81bbfcd72ea944f0c9e5ae848fd691b4eada5715 100644 (file)
@@ -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);
+    }
   });
 }