synclink icon indicating copy to clipboard operation
synclink copied to clipboard

Better error stack traces

Open hoodmane opened this issue 2 years ago • 5 comments

  • [ ] Add/Update tests

Given:

worker.js

importScripts("./iife/synclink.js");

function f(){
    throw new Error("hi!");
}
function g(){
    f();
}
function h() {
    g();
}

Synclink.expose(h);

main.js

const Synclink = await import("./esm/synclink.mjs");
let w = Synclink.wrap(new Worker("worker.js"))
async function v() {
    await w();
}
async function u() {
    await v();
}
await u()

Before Chrome:

Uncaught Error: hi!
    at f (worker.js:4:11)
    at g (worker.js:7:5)
    at h (worker.js:10:5)
    at innerMessageHandler (synclink.js:507:29)
    at synclink.js:569:25
    at Generator.next (<anonymous>)
    at synclink.js:56:63
    at new Promise (<anonymous>)
    at __async (synclink.js:40:12)
    at callback (synclink.js:548:14)

After Chrome:

Uncaught Error: hi!
    at f (worker.js:4:11)
    at g (worker.js:7:5)
    at h (worker.js:10:5)
    at SynclinkTask.do_async (task.ts:201:12)
    at async v (main.js:4:5)
    at async u (main.js:7:5)
    at async main.js:10:1

Before firefox:

Uncaught Error: hi!
    f http://localhost:8002/worker.js:4
    g http://localhost:8002/worker.js:7
    h http://localhost:8002/worker.js:10
    innerMessageHandler http://localhost:8002/iife/synclink.js:507
    callback http://localhost:8002/iife/synclink.js:569
    __async http://localhost:8002/iife/synclink.js:56
    __async http://localhost:8002/iife/synclink.js:40
    callback http://localhost:8002/iife/synclink.js:548

After firefox:

Uncaught Error: hi!
    f worker.js:4
    g worker.js:7
    h worker.js:10
    then task.ts:107
    promise callback*v main.js:4
    u main.js:7
    <anonymous> main.js:10

@antocuni

hoodmane avatar May 16 '23 05:05 hoodmane

wow, this is brilliant 😍

antocuni avatar May 16 '23 08:05 antocuni

It seems that I'm getting the same traceback twice. I had to slightly change your example in order to load it with chrome:

// main.js
async function main() {

    const Synclink = await import("./esm/synclink.mjs");
    let w = Synclink.wrap(new Worker("worker.js"))
    async function v() {
        await w();
    }
    async function u() {
        await v();
    }
    await u();

}
<!-- index.html -->
<html>
  <head>
    <script src="./main.js"></script>
    <script>
      main();
    </script>
  </head>
</html>

If I load index.html in chrome, I get the following: image

antocuni avatar May 16 '23 12:05 antocuni

Yeah I'm not sure why it shows it a second time... I think it has something to do with the top level await?

hoodmane avatar May 16 '23 14:05 hoodmane

Ah but you got rid of the top level await (you need to load it as an es6 module for it to work) and got the double traceback anyways.

hoodmane avatar May 16 '23 14:05 hoodmane

FWIW, on firefox it shows only once

antocuni avatar May 16 '23 15:05 antocuni