N12

Error

Requests

N12 — An error enum that is not shaped as one

An error enum names the statuses a service answers with, each a case carrying the body of its status, and keeps one http(error: HttpError) case for everything else — no network, a timeout, a status it does not name. A case with no status or more than one value, a status named twice, or no http case leaves a failure with nowhere to go.

What the compiler said

error[N12]: `SaveError` names a status, so it is an error enum, and keeps no `http` case --> src/App.wf:3:1 | 3 | enum SaveError { | ^^^^^^^^^^^^^^^^ = help: Add `http(error: HttpError)`: what goes wrong that no case names — no network, a timeout, another status — arrives there = docs: https://webfluent.monzeromer.dev/errors/N12

Your editor offers this fix: Add http(error: HttpError). wf fix --code N12 applies it to every place it fits.

The fix

Broken

wf

type Problem2 { title: String } enum SaveError { conflict(problem: Problem2) on 409 } page P(path: "/", title: "T", description: "D") { state last: SaveError? = null Heading("Save").h1 Text("{last == null}") }

Fixed

wf

type Problem2 { title: String } enum SaveError { conflict(problem: Problem2) on 409 http(error: HttpError) } page P(path: "/", title: "T", description: "D") { state last: SaveError? = null Heading("Save").h1 Text("{last == null}") }

Add the http(error: HttpError) case, give each other case one value and its status, and keep each status to one case.

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.

An error enum is what an endpoint declared -> T ! E fails with. Each status the service answers with is a case of its own, on its status, carrying the body that status sends; and one case, http(error: HttpError), takes everything else — no network, a timeout, a status no case names. An enum that names a status is an error enum, and is held to that shape:

  • exactly one http(error: HttpError) case, which names no status;
  • every other case names its status and carries one value;
  • no status named twice.

An endpoint may also be declared -> T!, when the service declares no statuses of its own: it fails with an HttpError.

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