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

Top level async/await doesn't work in JavaScript runtime #44

Open
mlejva opened this issue Oct 25, 2024 · 6 comments
Open

Top level async/await doesn't work in JavaScript runtime #44

mlejva opened this issue Oct 25, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@mlejva
Copy link
Member

mlejva commented Oct 25, 2024

When running JS code in the Sandbox, the top level promise is never awaited:

import { Sandbox } from '@e2b/code-interpreter'

const sandbox = await Sandbox.create({apiKey: ''})

const code = `
 const printResult = async () => {
      return 'foo';
    };

  printResult()
    .then((result) => {
      console.log("glama.result");
    })
    .catch((error) => {
      console.log("glama.error");
    });
`

console.log('running code')
const ex = await sandbox.runCode(code, {
  language: 'js',
  onError: (error) => {
    console.log('error', error)
  },
  onStdout: (stdout) => {
    console.log('stdout', stdout)
  },
  onStderr: (stderr) => {
    console.log('stderr', stderr)
  },
})
console.log('code executed', ex)

The code above will produce a following output

running code
code executed Execution {
  results: [
    Result {
      isMainResult: true,
      text: 'Promise { <pending> }',
      html: undefined,
      markdown: undefined,
      svg: undefined,
      png: undefined,
      jpeg: undefined,
      pdf: undefined,
      latex: undefined,
      json: undefined,
      javascript: undefined,
      raw: [Object],
      data: undefined,
      chart: undefined,
      extra: {}
    }
  ],
  logs: { stdout: [], stderr: [] },
  error: undefined,
  executionCount: 2
}

The text field says 'Promise { <pending> }' which means the promise was never awaited.

Copy link

linear bot commented Oct 25, 2024

@punkpeye
Copy link

There is no top-level await in this code by the way.

Anyway, is there a workaround – I just need to call a function that results Promise and get that response somehow.

@mlejva
Copy link
Member Author

mlejva commented Oct 25, 2024

There is no top-level await in this code by the way.

I should have clarified. There's a top level promise that isn't ever awaited.

Anyway, is there a workaround – I just need to call a function that results Promise and get that response somehow.

@jakubno is looking how we can fix it. One of the potential fixes is using a different kernel. We're looking at other kernels, ideally with TypeScript support.

@mlejva
Copy link
Member Author

mlejva commented Oct 28, 2024

@punkpeye we're adding a new JS kernel in this branch https://github.com/e2b-dev/code-interpreter/tree/change-js-kernel

@punkpeye
Copy link

punkpeye commented Nov 4, 2024

Says not-found.

Also, that Kernel worked completely fine. Looks like no one just read the documentation.

@mlejva
Copy link
Member Author

mlejva commented Nov 4, 2024

Says not-found.

Also, that Kernel worked completely fine. Looks like no one just read the documentation.

It got merged - 5894232
It's Deno. We're also looking at other kernels.

Still in preview though.

@ValentaTomas ValentaTomas added the bug Something isn't working label Nov 20, 2024
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

3 participants