Wasm error using time::now()

I am using seed.
I am looking for a simple way to put time stamps into my console logs.
Coming from C and Perl I was looking for something C-like and am using the crate time version 0.1
I am getting a error client side if I use the code:

fn my_now() -> String {
  let tm = time::now()
  return format!("{}", tm.rfc3339())
}

The error that is displayed in the browser console makes very little sense to me:

panicked at 'not implemented', /home/patch/.cargo/registry/src/github.com-1285ae84e5963aae/time-0.1.43/src/sys.rs:101:9

Stack:

init/imports.wbg.__wbg_new_55102f737bfb2abd<@http://patchbox.local:8000/pkg/package.js:1104:19
logError/<@http://patchbox.local:8000/pkg/package.js:216:22
console_error_panic_hook::Error::new::h05cac87939647d5e@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[7491]:0x1c1c23
console_error_panic_hook::hook_impl::h62501275fb7ba51c@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[1005]:0xeb454
console_error_panic_hook::hook::h54f80bf17652bb34@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[8398]:0x1ce1b0
core::ops::function::Fn::call::hc18cc83e26219f9c@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[6885]:0x1b86c9
std::panicking::rust_panic_with_hook::h4f753dc70b771d8e@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[1853]:0x1291d4
std::panicking::begin_panic_handler::{{closure}}::h5c9fc29957309ae8@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[3066]:0x15eb96
std::sys_common::backtrace::__rust_end_short_backtrace::h92808941d97e9b21@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[8734]:0x1d232f
rust_begin_unwind@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[7922]:0x1c7dbe
core::panicking::panic_fmt::hbd8a975261a5f466@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[8735]:0x1d2365
core::panicking::panic::h8e74859c8f9988ca@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[6854]:0x1b7efb
time::sys::inner::get_time::h15439e845488feb6@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[9238]:0x1d73bb
time::get_time::hf5d78f4ead104e3b@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[3648]:0x17180d
time::now::h54f7005f6cb6f2f7@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[6853]:0x1b7e8c
frontend::my_now::h39778d3b6ae6393e@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[3006]:0x15c97c
frontend::init::h5cf5c564031b3f87@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[253]:0x62792
core::ops::function::FnOnce::call_once::h786dc48e3ff96cec@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[5625]:0x1a1822
seed::app::App<Ms,Mdl,INodes>::start::h9bf4401e44aed18a@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[210]:0x44b45
frontend::start::hd7996e60b9f1dc0a@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[4222]:0x181560
start@http://patchbox.local:8000/pkg/package_bg.wasm:wasm-function[8494]:0x1cf5da
init@http://patchbox.local:8000/pkg/package.js:1178:10


package.js:1098:21
    __wbg_error_761a8766266ddc20 http://patchbox.local:8000/pkg/package.js:1098
    logError http://patchbox.local:8000/pkg/package.js:216
    hfcb95a9bcab37e44 http://patchbox.local:8000/pkg/package_bg.wasm:1371028
    h62501275fb7ba51c http://patchbox.local:8000/pkg/package_bg.wasm:963901
    h54f80bf17652bb34 http://patchbox.local:8000/pkg/package_bg.wasm:1892784
    hc18cc83e26219f9c http://patchbox.local:8000/pkg/package_bg.wasm:1803977
    h4f753dc70b771d8e http://patchbox.local:8000/pkg/package_bg.wasm:1216980
    h5c9fc29957309ae8 http://patchbox.local:8000/pkg/package_bg.wasm:1436566
    h92808941d97e9b21 http://patchbox.local:8000/pkg/package_bg.wasm:1909551
    rust_begin_unwind http://patchbox.local:8000/pkg/package_bg.wasm:1867198
    hbd8a975261a5f466 http://patchbox.local:8000/pkg/package_bg.wasm:1909605
    h8e74859c8f9988ca http://patchbox.local:8000/pkg/package_bg.wasm:1801979
    h15439e845488feb6 http://patchbox.local:8000/pkg/package_bg.wasm:1930171
    hf5d78f4ead104e3b http://patchbox.local:8000/pkg/package_bg.wasm:1513485
    h54f7005f6cb6f2f7 http://patchbox.local:8000/pkg/package_bg.wasm:1801868
    h39778d3b6ae6393e http://patchbox.local:8000/pkg/package_bg.wasm:1427836
    h5cf5c564031b3f87 http://patchbox.local:8000/pkg/package_bg.wasm:403346
    h786dc48e3ff96cec http://patchbox.local:8000/pkg/package_bg.wasm:1710114
    h9bf4401e44aed18a http://patchbox.local:8000/pkg/package_bg.wasm:281413
    hd7996e60b9f1dc0a http://patchbox.local:8000/pkg/package_bg.wasm:1578336
    start http://patchbox.local:8000/pkg/package_bg.wasm:1897946
    init http://patchbox.local:8000/pkg/package.js:1178
Uncaught (in promise) RuntimeError: unreachable executed
    init http://patchbox.local:8000/pkg/package.js:1178
package_bg.wasm:1947409:1

https://docs.rs/crate/time/0.1.43/source/src/sys.rs

The time@0.1 is rather old crate, it seems it only supports the WASM target with the emscripten behinds it as an OS api.

The chrono supports wasm-unknown-unknown target via the js-sys integration. To use it you need to enable wasmbind feature as stated in its document.

https://docs.rs/chrono/0.4.19/chrono/#features

Helpful, thanks.

How do I tell what crates I can safely use with wasm?

I was under the impression that this was not a issue, obviously wrong!

Time 0.1 does not support wasm. Time 0.2 does if you're able to upgrade.

This might be the issue: The wasm-unknown target doesn't support SystemTime::now()

That's only the case if you were to target a generic wasm platform. For web specifically, there are options.

(Speaking as the maintainer of the time crate)

I specifically meant wasm-unknown-unknown.

In some webassembly code I wrote for that I ended up pulling the system time in from js.

Hi

It is clear that time V0.1 is not compatible with wasm. Ok.

How can you tell, from a crate's page on crates.io what crates are and are not compatible? That, now, is the pertinent question

I don't think you can tell.

It's not the crates really, as the wasm-unknown-unknown platform doesn't have certain features (no specified OS) so even bits of the standard library, like SystemTime::now(), do not work on it.

1 Like

crates.io doesn't provide any information about what targets a crate supports, as it doesn't even know. You could request the author put it in the README I suppose.

In this case, time 0.1 has been deprecated and largely unmaintained for years, so I certainly won't be putting out another release just to update the README. And for the upcoming 0.3 release I've no plans to have info like this in the README either, as there will be a much larger document with far more detail on a number of items.

2 Likes