]> git.cworth.org Git - zombocom-ai/commitdiff
Make any code execution errors visible to the users
authorCarl Worth <cworth@cworth.org>
Fri, 23 Dec 2022 19:49:29 +0000 (11:49 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 23 Dec 2022 19:51:10 +0000 (11:51 -0800)
By sending them to the clients and having them render it in red
monospace with pre-wrapped whitespace.

This should allow the players to debug things when they don't work.

bus.html
index.js

index 5760786ec2a8dc2642dcc6d1fdc59e0856296430..40e50d38b6aab2ebf6ec8eab755cd98f1f7737df 100644 (file)
--- a/bus.html
+++ b/bus.html
     #output {
        width: 100%;
     }
+    #error {
+       font-family: monospace;
+       color: red;
+       white-space: pre-wrap;
+    }
   </style>
 </head>
 
        <textarea id="code" rows="15" width="100%"></textarea>
        <button type="submit">Run code</button>
       </form>
+      <div id="error">
+      </div>
       <img id="output"></img>
-    </div>
+   </div>
 
     <button id="jumpstart">
       Jumpstart Magic School Bus
     const welcome_message = document.getElementById("welcome-message");
     const jumpstart = document.getElementById("jumpstart");
     const output = document.getElementById("output");
+    const error = document.getElementById("error");
 
     function fade_element(elt) {
        elt.style.opacity = "100%";
        }
     });
 
+    socket.on('error', (error_message) => {
+       error.textContent = error_message;
+    });
+
     socket.on('state', (state) => {
        if (state === "program") {
            welcome.style.visibility = "hidden";
     });
 
     socket.on('output', (filename) => {
+       error.textContent = "";
        output.src = filename;
     });
 
index 2f990748b218d9bc37b4cc5872aa6e793bf83197..bfa6d8a1b76342d9a33e8a5469b2ce8523fd1435 100644 (file)
--- a/index.js
+++ b/index.js
@@ -300,7 +300,8 @@ io_bus.on("connection", (socket) => {
            // Give all clients the new image
            io_bus.emit('output', filename);
        } catch (e) {
-           console.log("Error executing turtle script: " + e);
+           // Send any error out to the users
+           io_bus.emit('error', e.toString())
        }
     });