-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
provide better panic message for Zoned::now
on wasm32-unknown-unknown
when js
feature is not enabled
#296
Comments
Yeah I do sympathize with this, but I unfortunately think that the "right" solution to this problem is for Rust (upstream) to have a wasm web target. And Jiff's design was loosely inspired by what One of the primary problems I have with enabling
I would actually potentially be open to this as long as it only runs on wasm and it... actually works. Will |
wasm32v1-none is a pure-
FWIW, as a user who'd had to engage in some careful dependency gardening to keep wasm-bindgen code out of my non-browser-targeted wasm module, I fully agree with this. |
Aye thanks for that added context @hanna-kruppe! So I think to me, it sounds like the only other lever to pull here is docs. I honestly don't have a good sense of how many people are actually using Jiff in a web browser context, but I've heard of at least a handful. Maybe something that is somewhat more prominent in the README? Or the crate docs? I thought there were other crates that followed this I also don't understand why
I have guesses about the rename, but I don't understand the searches the Oh! Hi @hanna-kruppe :-) rust-random/getrandom#433 (comment) It looks like probably not? Since Jiff doesn't need to support anything similar to the "alternative backends" that And also, TIL: rust-lang/cargo#10801 Actually, more like TILA (Today I Learned Again) because of BurntSushi/bstr#130 lol (Sorry for the slight ramble.) |
I appreciate the response, I didn't think at all about feature unification and the issues that may cause.
I wonder if unwinding is even needed? |
I would be very skeptical of setting panic hooks in a library like Jiff. That seems like speed-running a way toward pissing a whole bunch of people off. Panic hooks are very specifically a global resource. I acknowledge that And imagine if someone uses Jiff and |
I want to be clear that I acknowledge the bad failure mode you ran into. And I appreciate you brainstorming ways to fix it. :-) I really do think that for the time being, the best mitigation here is going to be docs. Which is all sorts of imperfect, especially when there are so many docs. But I don't think we can really do much better here presently without a cure that is worse than the disease. |
There is one other thing that jiff could try doing: whenever it calls #[cfg(all(target_family = "wasm", ..., not(feature = "js")))]
panic!("getting the current time in wasm32-unknown-unknown is not possible,\
enable jiff's `js` feature if you are targeting a browser environment");
let now = SystemTime::now(); |
Oh, well that seems fine then. I guess that makes sense because we know it will presumably always panic even in the future? That would be much better. Great idea. |
Yeah, I expect that if a “wasm-web” target is added in the future, it’ll at least differ in one of the |
js
feature defaultZoned::now
on wasm32-unknown-unknown
when js
feature is not enabled
Hi! First off, thanks for publishing this excellent library.
jiff
's current Wasm-in-browser support requires enabling a feature flag,js
. This makes a lot of sense! While the intentions are good, the feature flag unfortunately leads to a sub-optimal user experience. It's a silent failure mode, meaning it's not obvious as a new user of this library that it is required to make it work in a browser. In my first attempt to usejiff
in a Wasm-in-browser environment, I ran into the following panic:After some digging through docs, I discovered the
js
feature flag, enabled it, and all was well again. Later on, one of my colleagues ran into the same issue. I have a few more anecdotes like this, but the point is that the feature flag has poor discoverability.I believe the most common use case for Rust Wasm is running the code in a browser, so my suggestion is to make
js
a default feature. It would still allow people to disable it, but the "happy path" would be better supported, andjiff
would lead more people into the pit of success. The new failure mode would be the generated Wasm binary requiring additional imports that the host can't provide, so it would fail to load in non-browser environments. And of course, people disabling default features when adding new dependencies may still run into the same issue.The alternatives are to somehow better detect the environment, or improve the error message:
jiff
to unconditionally importDate.now
and just not use it if it wasn't provided. That feature has not received any attention for quite a while now, though.std
,jiff
couldcatch_unwind
the panic, inspect the error message for "time not implemented on this platform", modify it to provide additional context, and resume the panic. That seems extremely brittle, because changing the message would break the detection.Improving documentation and making the
js
feature more prominent there may help as well, but it's not clear how to get people to read the docs :)The text was updated successfully, but these errors were encountered: