-
Notifications
You must be signed in to change notification settings - Fork 533
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
format paniced #1363
Comments
What is the panic message? |
panic occurred: panicked at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/string.rs:2460:14: there are code use worker::*;
use chrono::NaiveDateTime;
use std::panic;
#[event(fetch)]
async fn main(req: Request, env: Env, ctx: Context) -> Result<Response> {
panic::set_hook(Box::new(|panic_info| {
console_error!("panic occurred: {panic_info}");
}));
let now = NaiveDateTime::from_timestamp_millis(Date::now().as_millis() as i64).unwrap();
Response::ok(now.format("%Y-%m-%dT%H:%M:%S%.f%:z").to_string())
} |
I'd like a full back trace, please -- I can't easily reproduce a WASM environment. |
Sorry but how to get full back trace? I call |
Usually with a |
I tried creating a test.
Date::now() doesn't exist for me on windows, I haven't setup a WASM build yet. I tried using NaiveDate::now() that also is not there. I can't compile the code provided at least on windows anyway. |
use chrono::NaiveDateTime;
fn main() {
let t = NaiveDateTime::from_timestamp_millis(1662921288000).unwrap();
let f = t.format("%+").to_string();
println!("{f}");
}
|
Well, that trace has no chrono stack frames, so it doesn't help much. :( |
Can you test it with I think the issue is |
it works, didn't panic |
Thank you for testing. That would make this issue a duplicate of #1096, and #1127 has the plan to return an error instead of panicking. In your case you just want to convert a Unix timestamp to RFC 3339 format? Than something like this should do the trick: use chrono::{Utc, TimeZone};
let response_str = Utc.timestamp_millis_opt(1662921288000).unwrap().to_rfc3339(); |
I use chrono to translate timestamp to ISO format string in wasm program. And panic when call format function.
There was code
Cargo.toml
wrangler.toml
The text was updated successfully, but these errors were encountered: