soma.cell

E0070: request_signature

E0070 request_signature — on request with a signature serve cannot call.

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

The rule

When on request declares a fourth or fifth parameter, they receive the URL query and the request headers as a Map of String to String, so they must be declared Map, Map<String, String> or Any. soma serve refuses the same signature at start-up, so check reports it first. Declare the parameter headers: Map and read a header by its lower-case name, such as headers["user-agent"].

A program that triggers it

wrong.cell

cell Api {
    on request(method: String, path: String, body: String, query: Map, headers: String) {
        return map("path", path, "agent", headers)
    }
}

What soma check prints:

$ soma check wrong.cell
error: `request`'s parameter `headers` receives the request headers as a Map of String to String: declare it `headers: Map` (or `Map<String, String>` / `Any`; it declares `String`)
  --> wrong.cell:2:5
  |
2 |     on request(method: String, path: String, body: String, query…
  |     ^
  = code: E0070
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: `request`'s parameter `headers` receives the request headers as a Map of String to String: declare it `headers: Map` (or `Map<String, String>` / `Any`; it declares `String`)

Lines 2–3 are rewritten.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -1,5 +1,5 @@
 cell Api {
-    on request(method: String, path: String, body: String, query: Map, headers: String) {
-        return map("path", path, "agent", headers)
+    on request(method: String, path: String, body: String, query: Map, headers: Map) {
+        return map("path", path, "agent", headers["user-agent"] ?? "unknown")
     }
 }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.