Error codes · Declarations and their clauses
PW0367
who_may_run
The program must hold to this: a command a reader can run says who may: requires and the predicates every request must hold, or requires Anyone, which stands alone and is the platform's.
A program the compiler refuses with it
module admin
opaque type PostId = String
type Post = Post { id: PostId, text: String }
type PostError =
| Missing
fn remove(post: PostId) -> Result<(), PostError> !{ database.write<Post> }
host "blog:data/posts#remove"
command delete_post(post: PostId) -> Result<(), PostError> {
remove(post)
}error: [PW0367] `delete_post` runs for any reader's request, and says nothing of who may run it
--> admin.pw:13:9
|
13 | command delete_post(post: PostId) -> Result<(), PostError> {
| - ^^^^^^^^^^^ `delete_post` runs for any reader's request, and says nothing of who may run it
| _|
| |
14 | | remove(post)
15 | | }
| |_- a request that names `delete_post` runs it, with or without a page
|
= note: The server runs a command for any request that names it, whether or not a page shows its button: a request is an address and a body, and anyone can send one. So who may run a command is the command's to say. `requires` names what every request must hold, as `requires SignedIn, OwnsPost(post)`; `requires Anyone` says anyone may, and stands alone. A command the platform runs says `invoked_by` instead.
= help: declare `requires` with what a reader must hold, such as `requires SignedIn`
= help: or `requires Anyone`, if anyone may run itFrom A command anyone can run, by saying nothing, in Errors and diagnostics. A test holds the guide's examples to the compiler.
The decisions behind it
Reading the diagnostic
pw check prints the code in brackets, [PW0367], with the sentence above and the place in your program. Errors and diagnostics explains how to read one, and every code is listed with its rule.