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

Better error stack traces #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

hoodmane
Copy link
Member

@hoodmane hoodmane commented May 16, 2023

  • 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

@antocuni
Copy link
Collaborator

wow, this is brilliant 😍

@antocuni
Copy link
Collaborator

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

@hoodmane
Copy link
Member Author

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
Copy link
Member Author

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.

@antocuni
Copy link
Collaborator

FWIW, on firefox it shows only once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants