Code Monkey home page Code Monkey logo

Comments (6)

erights avatar erights commented on July 18, 2024

Added the 1.0-blocker label. But not that we do not need a fully function debugging experience to unblock 1.0. Progress could unblock even if this bug remains open for remaining problems.

from endo.

warner avatar warner commented on July 18, 2024

There are two things which might help:

  • we just landed an option named errorStackMode: "allow" (or rather we fixed it to stop breaking exceptions quite so badly). When you enable this, Error objects ought to retain their name and stack data. But it also might open up a confinement leak, as it leaves some non-standard properties on the Error prototype (which V8 needs to produce stack traces).
  • we're looking at a patch to the Realms shim that would attach the source of each evaluated string as a "source map". This may or may not help give more information to a debugger.. we haven't been able to test it properly yet.

The patch would look like this:

diff --git a/shim/src/evaluators.js b/shim/src/evaluators.js
index 8b4fe9a..0e0fc32 100644
--- a/shim/src/evaluators.js
+++ b/shim/src/evaluators.js
@@ -94,6 +94,8 @@ export function createSafeEvaluatorFactory(unsafeRec, safeGlobal) {
     const safeEval = {
       eval(src) {
         src = `${src}`;
+        const sourceURL = `data:,${encodeURIComponent(src)}`;
+        src += `\n//# sourceURL='${sourceURL}'\n`;
         rejectImportExpressions(src);
         scopeHandler.allowUnsafeEvaluatorOnce();
         let err;

It wants to live in Realms, but we might also be able to add it to SES instead. Also it kinda wants to be provided as a third argument to the r.evaluate() or SES.confine() call (the first is the source code, the second is the endowments, and the third would be an options bundle, of which sourceURL: or source: could include this stuff).

What we learned about errorStackMode is that our default (which deletes the non-standard properties from Error) breaks exception rendering pretty badly: Node.js at least doesn't show anything, not even the name and message of the exception. Your process just terminates abruptly with a line that says undefined. So my current advice is that if your process is exiting this way, change your code to use SES.makeSESRootRealm({errorStackMode: 'allow'}) until you fix the problem, then turn that back off again before you let it run untrusted code.

The other thing we learned is that there are a lot of eval() going on, so the stack traces usually point at line numbers inside anonymous strings. If you happen to stash a copy of the string you pass into r.evaluate(), then the line number ought to match up with that, but in a lot of cases that string is thrown away. This will hopefully get better when we implement more of a module loader, so you can pass a module or a filename into evaluate() or confine(), in which case the eval'ed source code can point to a file, from which line numbers can come. The tricky bit is that we must make sure this doesn't lead to a confinement leak: a process should not be able to learn the contents of an external file by throwing an exception, and an exception on one side of a trust boundary should not reveal excess information to a caller on the other side.

And debugging, in general, is a special power, which should come from the top-most "primal" realm, and get virtualized as you make new realms inside that. We have some old E work on this to draw from, but it'll be a while before we get this figured out in the JS context.

from endo.

dckc avatar dckc commented on July 18, 2024

Monte draws from that E work: exceptions are sealed and a special debugging power, unsealException, is passed to the top-level main entry point.

Monte's trace facility also has the power to unseal exceptions. (that's perhaps more relevant to #148 on console.log ...)

from endo.

dckc avatar dckc commented on July 18, 2024

@michaelfig does the technique in Agoric/SwingSet#158 apply here, by chance?

from endo.

michaelfig avatar michaelfig commented on July 18, 2024

It does, insofar as the filename is attached via a sourceURL to the string you're evaluating. This is the "module loader provides URLs" solution.

from endo.

kriskowal avatar kriskowal commented on July 18, 2024

SES now carries sourceURL and has taming options for errors. Please reopen if this issue is still relevant.

from endo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.