soma.cell

E0047: unknown_state

E0047 unknown_state — a state name the machine does not declare.

A compile-time error of soma check, the checker of the Soma programming language (soma explain E0047).

The rule

The except [ … ] list of a wildcard transition (* -> cancelled except [shipped, delivered]) names a state that no transition of the machine declares. Such a name excepts nothing, so the wildcard would still add an edge from the state the author meant to protect. Fix the spelling so the list names declared states. A misspelt state in a transition() call is reported separately, as E0027.

A program that triggers it

wrong.cell

cell Orders {
    state lifecycle {
        initial: placed
        placed -> paid
        paid -> shipped
        shipped -> delivered
        * -> cancelled except [shiped, delivered]
    }
    on pay(id: String) { transition(id, "paid") }
    on ship(id: String) { transition(id, "shipped") }
    on deliver(id: String) { transition(id, "delivered") }
    on cancel(id: String) { transition(id, "cancelled") }
}

What soma check prints:

$ soma check wrong.cell
error: `* -> cancelled except [shiped, delivered]` names 'shiped' (did you mean 'shipped'?), which no transition of `state lifecycle` declares — it excepts nothing
  --> wrong.cell:7:9
  |
7 |         * -> cancelled except [shiped, delivered]
  |         ^
  = code: E0047
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: it excepts nothing

On line 7, * -> cancelled except [shiped, delivered] becomes * -> cancelled except [shipped, delivered].

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -5,5 +5,5 @@
         paid -> shipped
         shipped -> delivered
-        * -> cancelled except [shiped, delivered]
+        * -> cancelled except [shipped, delivered]
     }
     on pay(id: String) { transition(id, "paid") }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.