T21

Error

Types

T21 — A read's match with no .failed arm

When the first request fails, a match over a read with no .failed arm and no else shows nothing at all, and the reader is not told.

What the compiler said

error[T21]: this `match` on `users` has no `.failed` arm and no `else`, so a failed request shows nothing --> src/App.wf:6:5 | 6 | match users { | ^^^^^ = help: Add `.failed(e) { Alert(e.message).danger }`, or `else { … }` = docs: https://webfluent.monzeromer.dev/errors/T21

Your editor offers this fix: Add an arm for .failed. wf fix --code T21 applies it to every place it fits.

The fix

Broken

wf

type User { name: String } page P(path: "/", title: "T", description: "D") { resource users: [User] = http.get("/api/users") Heading("Users").h1 match users { .loading { Spinner } .loaded(list) { Text("{list.length} users") } } }

Fixed

wf

type User { name: String } page P(path: "/", title: "T", description: "D") { resource users: [User] = http.get("/api/users") Heading("Users").h1 match users { .loading { Spinner } .failed(e) { Alert(e.message).danger } .loaded(list) { Text("{list.length} users") } } }

.failed(e) { Alert(e.message).danger }, or an else. The editor's quick fix and wf fix --code T21 add an arm for every case the match leaves out.

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

Error.

A read is .loading, .failed(e) or .loaded(value). A first load that fails is .failed(e); with no arm for it, the place stays empty and the reader is never told. A match that misses .loading or .loaded is T15.

lints cannot lower it: it would ship a broken page.