Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XSnap REPL #9955

Open
kriskowal opened this issue Aug 23, 2024 · 9 comments
Open

XSnap REPL #9955

kriskowal opened this issue Aug 23, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@kriskowal
Copy link
Member

Describe the bug

The xsrepl tool for debugging xsnap has been broken for some time.

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'packages/xsnap'
  2. Run yarn xsrepl

Expected behavior

This should open up a CLI REPL you can use to send commands to an xsnap process. It’s useful for debugging xsnap.

Platform Environment

  • agoric-sdk 5cd99eae25a3194dd04e77bc5bae23cd9ead981d

Additional context

The tool doesn’t have validation in CI so is doomed to rot. We should either delete it or CI it.

@kriskowal kriskowal added the bug Something isn't working label Aug 23, 2024
@mhofman
Copy link
Member

mhofman commented Aug 27, 2024

I used this fairly recently, maybe a few weeks ago, what's broken about it?

@mhofman
Copy link
Member

mhofman commented Aug 27, 2024

I just verified that it's working for me on master as of 7a08c6af641c62d8b0ef4a0c35090b6216a5be34

@kriskowal
Copy link
Member Author

I’ve lost track of the circumstances this was originally reported on, but content that it’s working on master until we get a more specific isolation.

@erights
Copy link
Member

erights commented Sep 1, 2024

Steps to reproduce the behavior:

  1. Go to 'packages/xsnap'
  2. Run yarn xsrepl

Doing that runs the xsrepl at agoric-sdk/node_modules/.bin/xsrepl. In that repl, a thrown error seems to cause that repl to hang forever, or until I type a control-C.

$ yarn xsrepl
yarn run v1.22.22
$ /Users/markmiller/src/ongithub/agoric/agoric-sdk/node_modules/.bin/xsrepl
xs> 2n/0n;
(Error#1)
Error#1: Uncaught exception in <unnamed xsnap worker>: RangeError: (anonymous-543): zero divider
  at runToIdle (file:///Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/xsnap/src/xsnap.js:334:15)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Indeed, in xsnap package.json scripts at

"scripts": {
"repl": "node src/xsrepl.js",

there is an entry for "repl": but no entry for "xsrepl":. So if I do a yarn repl, it does run src/xsrepl.js, but this also hangs forever on a thrown error:

$ yarn repl
yarn run v1.22.22
$ node src/xsrepl.js
xs> 2n/0n
(Error#1)
Error#1: Uncaught exception in <unnamed xsnap worker>: RangeError: (anonymous-543): zero divider
  at runToIdle (file:///Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/xsnap/src/xsnap.js:334:15)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Reopening.

@erights erights reopened this Sep 1, 2024
@erights
Copy link
Member

erights commented Sep 1, 2024

Attn @kriskowal @mhofman @phoddie

@phoddie
Copy link

phoddie commented Sep 9, 2024

Is there something Team Moddable should look at here?

@mhofman
Copy link
Member

mhofman commented Sep 9, 2024

I don't think there is anything Moddable needs to do here. We just need to better handle errors thrown in evaluated commands from our repl.

Arguably this should be filed as a separate issue.

@mhofman
Copy link
Member

mhofman commented Sep 9, 2024

Potential fix:

diff --git a/packages/xsnap/src/xsrepl.js b/packages/xsnap/src/xsrepl.js
index 3eede346bb..bfeece538b 100755
--- a/packages/xsnap/src/xsrepl.js
+++ b/packages/xsnap/src/xsrepl.js
@@ -31,7 +31,12 @@ async function main() {
    * @returns {Promise<Uint8Array>}
    */
   async function handleCommand(message) {
-    console.log(decoder.decode(message));
+    const { success, result, error } = JSON.parse(decoder.decode(message));
+    if (success) {
+      console.log(result);
+    } else {
+      console.error(error);
+    }
     return new Uint8Array();
   }
 
@@ -50,11 +55,22 @@ async function main() {
     });
     function handleCommand(request) {
       const command = new TextDecoder().decode(request);
-      let result = compartment.evaluate(command);
-      if (result === undefined) {
-        result = null;
+      let result;
+      let error;
+      let success;
+      try {
+        result = compartment.evaluate(command);
+        success = true;
+      } catch (e) {
+        success = false;
+        try {
+          const {name, message, stack} = e;
+          error = {name, message, stack};
+        } catch (_e) {
+          error = String(e);
+        }
       }
-      issueCommand(new TextEncoder().encode(JSON.stringify(result, null, 4)).buffer);
+      issueCommand(new TextEncoder().encode(JSON.stringify({success, result, error}, null, 4)).buffer);
     }
   `);

@erights
Copy link
Member

erights commented Sep 10, 2024

Time for a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants