soma.cell

E0052: transition_no_machine

E0052 transition_no_machine — transition() in a program without a state machine.

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

The rule

A handler calls transition(), get_status(), has_state() or valid_transitions() in a program that declares no state machine, or from a cell without a machine when the program has several. These calls read and move a machine's instances, so without one machine to resolve to they can only fail. Declare a state section in the cell that owns the lifecycle, or call a handler of the cell that owns the machine.

A program that triggers it

wrong.cell

cell Tickets {
    memory {
        titles: Map<String, String> [persistent]
    }
    on open_ticket(id: String, title: String) {
        titles.set(id, title)
        return id
    }
    on resolve(id: String) {
        transition(id, "resolved")
        return get_status(id)
    }
}

What soma check prints:

$ soma check wrong.cell
error: cell Tickets calls transition() but the program declares no state machine
  --> wrong.cell:10:9
   |
10 |         transition(id, "resolved")
   |         ^
  = code: E0052
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: cell Tickets calls transition() but the program declares no state machine

4 lines are added after line 3.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -2,4 +2,8 @@
     memory {
         titles: Map<String, String> [persistent]
+    }
+    state ticket {
+        initial: open
+        open -> resolved
     }
     on open_ticket(id: String, title: String) {

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.