cloudflare / cloudflare/workers-rs

[BUG] Using `env_logger` crashes the worker

Open
#696 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
3.7k
Forks
429
Avg merge
20h 28m
Merged PRs (30d)
7

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What version of `workers-rs` are you using?

0.5.0

### What version of `wrangler` are you using?

3.103.2

### Describe the bug

Trying to use [`env_logger`](https://docs.rs/env_logger/latest/env_logger/)'s but I cannot make it work.

`env_logger::init()` doesn't enable the work because `RUST_LOG` environment variable is not set ( I couldn't make it work, that's presumably because wasm doesn't have access to env?).

After that attempt I tried to use

```
env_logger::builder().filter_level(log::LevelFilter::Debug).init()
```

but that crashes the worker:

```
✘ [ERROR] service core:user:PROJECT: Uncaught RuntimeError: unreachable

at [object Object] in $func1519
at [object Object] in $func993
at [object Object] in $func1069
at [object Object] in $func1489
at [object Object] in $func1272
at [object Object] in $func1271
at [object Object] in $func1253
at [object Object] in $func259
at [object Object] in $func158
at [object Object] in $func204

✘ [ERROR] The Workers runtime failed to start. There is likely additional logging output above.
```

### Steps To Reproduce

Use `env_logger` in worker code, e.g.:

```
#[event(start)]
fn start() {
console_log!("Worker started successfully!");
// env_logger::init(); // Doesn't work
env_logger::builder().filter_level(log::LevelFilter::Debug).init(); // Crash
info!("Worker started successfully!");
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the #[event(start)] entry point and reproduce the failure using workers-rs 0.5.0 with wrangler 3.103.2, comparing env_logger::init() with the builder configuration shown. Trace the worker startup and logging path to identify why initialization reaches an unreachable runtime state; done means the worker starts successfully and emits the expected log message without requiring RUST_LOG.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
backend, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.