N04
Warning
Requests
N04 — A result nothing reads
await Backend.users.create(body: draft) written on its own drops what came back: whether the user was made, or why not. Match it, or pass a failure up with try.
What the compiler said
warning[N04]: what `await Backend.create(…)` answers is not read: whether it worked goes nowhere --> src/App.wf:9:9 | 9 | await Backend.create(title: title) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Match it — `match await … { .ok(v) { … } .err(e) { … } }` — or pass a failure up with `try await …` = docs: https://webfluent.monzeromer.dev/errors/N04
The fix
Broken
type Todo { id: String, title: String }
api Backend(base: "/api") {
post create(title: String) at "todos" -> Todo!
}
store Todos {
action add(title: String) {
await Backend.create(title: title)
}
}
page P(path: "/", title: "T", description: "D") {
use Todos
Heading("Todos").h1
Button("Add milk") { on click { Todos.add("Milk") } }
}
Fixed
type Todo { id: String, title: String }
api Backend(base: "/api") {
post create(title: String) at "todos" -> Todo!
}
store Todos {
state failed = ""
action add(title: String) {
match await Backend.create(title: title) {
.ok(_) { failed = "" }
.err(e) { failed = e.message }
}
}
}
page P(path: "/", title: "T", description: "D") {
use Todos
Heading("Todos").h1
Button("Add milk") { on click { Todos.add("Milk") } }
Text(Todos.failed)
}
match the result and say what happened in each case, or write
try await … in an action that declares an error, to pass a failure up to
whatever called it.
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
Why this rule exists
Warning.
A call of an endpoint never throws: it returns a result, .ok(value) or
.err(error). Awaited on its own, the result is dropped, and with it
whether the call worked. If the server refused the todo, or the network was
gone, nothing on the page says so.
lints may lower it:
"lints": { "N04": "off" }
// wf-allow(N04)