codec_missing: a value crosses the wire without a JSON codec
Sending a value to another node (Node.send, a remote actor’s message) encodes
it as JSON. Its type needs a codec, which derive Json for T provides. This
error names the type that has none.
A program that triggers it
mod Main do
needs IO.Console
needs IO.NetConnect
needs IO.Mut
type Job = { id : Int }
fn main(_c : Cap(IO.Console), _n : Cap(IO.NetConnect), _m : Cap(IO.Mut)) do
let peer : Peer = { node_id: "w", identity: NodeIdentity.make("w", "pk", 1), fd: 3, data_fd: -1 }
let job : Job = { id: 7 }
let _ = Node.send(peer, GlobalPid.make("w", 1, 1), job)
()
end
end
The fix
Derive the codec next to the type’s declaration:
mod Main do
needs IO.Console
needs IO.NetConnect
needs IO.Mut
type Job = { id : Int }
derive Json for Job
fn main(_c : Cap(IO.Console), _n : Cap(IO.NetConnect), _m : Cap(IO.Mut)) do
let peer : Peer = { node_id: "w", identity: NodeIdentity.make("w", "pk", 1), fd: 3, data_fd: -1 }
let job : Job = { id: 7 }
let _ = Node.send(peer, GlobalPid.make("w", 1, 1), job)
()
end
end
Why the rule exists
The receiver decodes with the same codec, and the codec fixes the wire format both sides agree on. Picking an encoding implicitly would make a type’s representation change silently when its definition does.
See also: the language reference.