summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2025-05-09 13:16:24 +0200
committerTor Andersson <tor@ccxvii.net>2025-05-12 00:09:39 +0200
commite0f06319afc4d77f1e6141f3b0cc840470e895c5 (patch)
tree01e95a9dfdf44a14e146f95808cf57e9f9a0cc8a
parent41e604f3eb306c2e74a9cfca6af32ce6a03a3eff (diff)
downloadserver-e0f06319afc4d77f1e6141f3b0cc840470e895c5.tar.gz
More framework error handling.
Docs typo.
-rw-r--r--docs/module/rules.md2
-rw-r--r--public/common/framework.js25
2 files changed, 19 insertions, 8 deletions
diff --git a/docs/module/rules.md b/docs/module/rules.md
index 7f9ae2d..427556c 100644
--- a/docs/module/rules.md
+++ b/docs/module/rules.md
@@ -255,7 +255,7 @@ to the state (from a nested state), and when the state is departed.
You can use this to do some house-keeping or initialize the L scope.
- S.state.remove_3_pieces = {
+ S.remove_3_pieces = {
_begin() {
L.count = 3
},
diff --git a/public/common/framework.js b/public/common/framework.js
index a1601b7..f0a1abe 100644
--- a/public/common/framework.js
+++ b/public/common/framework.js
@@ -225,12 +225,16 @@ function _run() {
for (var i = 0; i < 1000 && L; ++i) {
var prog = P[L.P]
if (prog) {
- if (typeof prog === "function")
+ if (typeof prog === "function") {
prog()
- else if (L.I < prog.length)
- prog[L.I++]()
- else
- end()
+ } else if (Array.isArray(prog)) {
+ if (L.I < prog.length)
+ prog[L.I++]()
+ else
+ end()
+ } else {
+ throw new Error("invalid procedure: P." + L.P)
+ }
} else {
return
}
@@ -483,12 +487,19 @@ function _parse(text) {
function script(text) {
script.cache ??= {}
+ var prog = []
try {
- return _parse(text).map(inst => script.cache[inst] ??= eval("(function(){" + inst + "})"))
+ for (var inst of _parse(text)) {
+ try {
+ prog.push(script.cache[inst] ??= eval("(function(){" + inst + "})"))
+ } catch (err) {
+ return err.message + " - " + inst
+ }
+ }
} catch (err) {
- // return the error message so we can attach the script name and re-raise later
return err.message
}
+ return prog
}
(function () {