nenu-lang / backend-effects
StableBackend Effects
- throw ends the current path with a failure.
- log takes a non-empty literal event name and one optional payload expression.
- cache supports get, set, and delete with a 15-minute default set TTL.
Throwing A Failure
code
1throw "Expense could not be processed"A throw terminates the current control-flow path. There is no public try, catch, or finally syntax in Nenu.
Logging
code
1log("Starting room balance rebuild")2log("Finished room balance rebuild", total)log takes a non-empty string literal event name followed by at most one payload expression. Use it for stable execution milestones and useful diagnostic context—not as a substitute for a return value, user-visible toast, or durable record.
| Need | Use |
|---|---|
| Backend diagnostic milestone | log("EventName", optional_payload) |
| Visible page feedback | toast.success, toast.warning, or toast.error |
| API success data | return Response { ... } |
| Durable audit history | A project entity saved explicitly |
Cache Operations
code
1cache.set("room-summary", summary)2cache.set("room-summary", summary, 3600)3cache.set("room-summary", summary, "1day")4cache.set("room-summary", summary, expires: "1day")56cache.get("room-summary")7cache.delete("room-summary")| Operation | Meaning |
|---|---|
cache.set(key, value) | Store with the default TTL of 15 minutes. |
cache.set(key, value, seconds) | Store with a numeric TTL in seconds. |
cache.set(key, value, duration) | Store with a supported duration string. |
cache.get(key) | Read the cached entry. |
cache.delete(key) | Remove the cached entry. |
Common Mistakes
| Wrong | Correct |
|---|---|
print("done") | log("done") |
try { ... } catch { ... } | Validate first and use throw for failure. |
Use log for a user message | Use a Page Script toast. |
Put cache reads in need {} | Call cache operations in runnable logic. |
| Use cache as the only copy of an expense | Persist authoritative data as entities. |
