sagemathinc / cowasm

CoWasm: Collaborative WebAssembly for Servers and Browsers. Built using Zig. Supports Python with extension modules, including numpy.
https://cowasm.org
BSD 3-Clause "New" or "Revised" License
503 stars 26 forks source link

wasi-js: warnings are printed to stdout #62

Open gerdstolpmann opened 1 year ago

gerdstolpmann commented 1 year ago

Hello,

I just switched from wasmer to wasi-js in the WasiCaml project (https://github.com/remixlabs/wasicaml). There are a lot of scripts running WASI-fied wasm code, and some of them also write to stdout. I found in the stdout of one script the string

cpu waiting for stdin: please define a way to sleep!

which causes the further build to fail. Obviously, this warning is from wasi-js and printed with console.log which goes to stdout. For scripting, this is very unfortunate - whereas messages in stderr are typically no problem. Can you switch to console.warn or console.error instead?

Btw, thanks for picking the code up and maintaining it.

gerdstolpmann commented 1 year ago

Looks like that there is a workaround: assign

console.log = console.error

just before starting wasm.

gerdstolpmann commented 1 year ago

Another remark: I got this warning when redirecting stdin to a file. The warning seems to be fairly inappropriate in this case - files never block. It might be better to move the warning a few lines downwards, where you call shortPause.

williamstein commented 1 year ago

Can you send me a PR changing to warn? I'm happy to quickly review it, merge it, and update the npm package.

And I agree with you and see how that output could be annoying. It was something I put in to avoid problems with my interactive REPL work (for https://cowasm.org and https://cowasm.sh) that builds on this. However, it's fine to change it to console.warn, console.error, or even remove it, at at this point.

Thanks for using wasi-js!

williamstein commented 1 year ago

Here's the relevant code: https://github.com/sagemathinc/cowasm/blob/main/core/wasi-js/src/wasi.ts#L950

gerdstolpmann commented 1 year ago

I'll take a look later today.