E0051: undefined_delegate
E0051 undefined_delegate — a route delegates to a handler that does not exist.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0051).
The rule
A delegate("Cell", "handler", …) call names a cell of this program that has no handler of that name, or passes a number of arguments the handler does not take. The call is resolved by name at run time, so soma check refuses it when both names are literals. Use the exact name of a handler of that cell. A delegate to a cell the program does not define is only a warning, since that cell may be loaded beside it.
A program that triggers it
wrong.cell
cell Billing {
on create_invoice(order_id: String, cents: Int) {
return map("order", order_id, "due_cents", cents)
}
}
cell Dispatcher {
on handle(kind: String, order_id: String, cents: Int) {
if kind == "invoice" {
return delegate("Billing", "invoice", order_id, cents)
}
return map("error", "unknown kind {kind}")
}
}What soma check prints:
$ soma check wrong.cell
error: delegate("Billing", "invoice", …): cell Billing has no handler 'invoice'
--> wrong.cell:10:29
|
10 | return delegate("Billing", "invoice", order_id, cents)
| ^
= code: E0051
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: delegate("Billing", "invoice", …): cell Billing has no handler 'invoice'
The fix
On line 10, return delegate("Billing", "invoice", order_id, cents) becomes return delegate("Billing", "create_invoice", order_id, cents).
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -8,5 +8,5 @@
on handle(kind: String, order_id: String, cents: Int) {
if kind == "invoice" {
- return delegate("Billing", "invoice", order_id, cents)
+ return delegate("Billing", "create_invoice", order_id, cents)
}
return map("error", "unknown kind {kind}")With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.