cloudflare / cloudflare/workers-rs

[BUG] Storage.get should return an easy-to-recognize error on not found

Open
#205 1 comment 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.0.9

### Describe the bug

`worker::State::get` returns `Err(JsError("No such value in storage."))` if a key was not found.

This should get its own enum in `Error`, or something like that. https://docs.rs/worker/latest/worker/enum.Error.html

In the Javascript world, it returns `undefined`: . By that logic, it could also return `Result>`, like https://docs.rs/sled/latest/sled/struct.Tree.html#method.get

Underlying requirement: make it easy to test whether a `get` error was caused by an actual error, or this being the first run.

Also, the documentation is wrong and looks like it was directly copy-pasted from Javascript: https://docs.rs/worker/latest/worker/durable/struct.Storage.html#method.get

### Steps To Reproduce

In a Durable Object, call https://docs.rs/worker/latest/worker/durable/struct.Storage.html#method.get with a nonexistent key.

```rust
let result: Result<(), worker::Error> = self.state.storage().get("does not exist").await;
console_log!("GOT {:?}", result);
```

```
GOT Err(JsError("No such value in storage."))
```

See https://github.com/cloudflare/workers-rs/blob/e3cb3e2b5ab1e63a84398535d4f3c3a1e45eaf5d/worker/src/durable.rs#L210

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.