Error codes · Caches, keys and invalidation
PW5107
optimistic_not_reconciled
The program must hold to this: a command invalidates the entry it speculates on, so what it committed replaces the speculation.
A program the compiler refuses with it
module feed.speculative
import context.{ current_session }
import capability.{ Session, SessionId }
opaque type InteractionId = String
type Post = Post { id: String, text: String }
type FeedError =
| Unavailable
fn latest() -> List<Post> !{ database.read<Post> }
host "feed:data/posts#latest"
fn publish(s: Session<SessionId>, text: String) -> Result<Post, FeedError> !{ database.write<Post> }
host "feed:data/posts#publish"
public query Latest() -> List<Post>
freshness 5.seconds
cache shared
{
latest()
}
fn with_post(posts: List<Post>, text: String) -> List<Post> !{} {
posts
}
command post(text: String) -> Result<Post, FeedError>
idempotent_by InteractionId
optimistic Latest() as posts => with_post(posts, text)
{
publish(current_session(), text)
}From Commands, in Data on the server. A test holds the guide's examples to the compiler.
The decisions behind it
Reading the diagnostic
pw check prints the code in brackets, [PW5107], 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.