Surface all errors: wrap event handlers in try/catch with console.error
- domAddListener wraps callbacks so exceptions always log to console - Add "sx:route trying <url>" log before tryClientRoute call - Remove redundant bind-event fired log (replaced with route-specific logs) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
||||||
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
|
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
|
||||||
var SX_VERSION = "2026-03-06T21:50:58Z";
|
var SX_VERSION = "2026-03-06T21:53:47Z";
|
||||||
|
|
||||||
function isNil(x) { return x === NIL || x === null || x === undefined; }
|
function isNil(x) { return x === NIL || x === null || x === undefined; }
|
||||||
function isSxTruthy(x) { return x !== false && !isNil(x); }
|
function isSxTruthy(x) { return x !== false && !isNil(x); }
|
||||||
@@ -1842,8 +1842,7 @@ return postSwap(target); });
|
|||||||
var timer = NIL;
|
var timer = NIL;
|
||||||
var lastVal = NIL;
|
var lastVal = NIL;
|
||||||
var listenTarget = (isSxTruthy(get(mods, "from")) ? domQuery(get(mods, "from")) : el);
|
var listenTarget = (isSxTruthy(get(mods, "from")) ? domQuery(get(mods, "from")) : el);
|
||||||
return (isSxTruthy(listenTarget) ? domAddListener(listenTarget, eventName, function(e) { logInfo((String("sx:bind-event fired: ") + String(eventName) + String(" on ") + String(domTagName(el))));
|
return (isSxTruthy(listenTarget) ? domAddListener(listenTarget, eventName, function(e) { return (function() {
|
||||||
return (function() {
|
|
||||||
var shouldFire = true;
|
var shouldFire = true;
|
||||||
if (isSxTruthy(get(mods, "changed"))) {
|
if (isSxTruthy(get(mods, "changed"))) {
|
||||||
(function() {
|
(function() {
|
||||||
@@ -1855,6 +1854,7 @@ return (function() {
|
|||||||
var isGetLink = (isSxTruthy((eventName == "click")) && isSxTruthy((get(verbInfo, "method") == "GET")) && isSxTruthy(domHasAttr(el, "href")) && !get(mods, "delay"));
|
var isGetLink = (isSxTruthy((eventName == "click")) && isSxTruthy((get(verbInfo, "method") == "GET")) && isSxTruthy(domHasAttr(el, "href")) && !get(mods, "delay"));
|
||||||
var clientRouted = false;
|
var clientRouted = false;
|
||||||
if (isSxTruthy(isGetLink)) {
|
if (isSxTruthy(isGetLink)) {
|
||||||
|
logInfo((String("sx:route trying ") + String(get(verbInfo, "url"))));
|
||||||
clientRouted = tryClientRoute(urlPathname(get(verbInfo, "url")));
|
clientRouted = tryClientRoute(urlPathname(get(verbInfo, "url")));
|
||||||
}
|
}
|
||||||
return (isSxTruthy(clientRouted) ? (browserPushState(get(verbInfo, "url")), browserScrollTo(0, 0)) : ((isSxTruthy(isGetLink) ? logInfo((String("sx:route server fetch ") + String(get(verbInfo, "url")))) : NIL), (isSxTruthy(get(mods, "delay")) ? (clearTimeout_(timer), (timer = setTimeout_(function() { return executeRequest(el, verbInfo, NIL); }, get(mods, "delay")))) : executeRequest(el, verbInfo, NIL))));
|
return (isSxTruthy(clientRouted) ? (browserPushState(get(verbInfo, "url")), browserScrollTo(0, 0)) : ((isSxTruthy(isGetLink) ? logInfo((String("sx:route server fetch ") + String(get(verbInfo, "url")))) : NIL), (isSxTruthy(get(mods, "delay")) ? (clearTimeout_(timer), (timer = setTimeout_(function() { return executeRequest(el, verbInfo, NIL); }, get(mods, "delay")))) : executeRequest(el, verbInfo, NIL))));
|
||||||
@@ -2993,7 +2993,9 @@ callExpr.push(dictGet(kwargs, k)); } }
|
|||||||
if (opts && !isNil(opts)) {
|
if (opts && !isNil(opts)) {
|
||||||
if (opts.once || opts["once"]) o.once = true;
|
if (opts.once || opts["once"]) o.once = true;
|
||||||
}
|
}
|
||||||
el.addEventListener(event, fn, o);
|
el.addEventListener(event, function(e) {
|
||||||
|
try { fn(e); } catch (err) { console.error("[sx-ref] event handler error:", event, err); }
|
||||||
|
}, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Validation ---
|
// --- Validation ---
|
||||||
|
|||||||
@@ -2514,7 +2514,9 @@ PLATFORM_ORCHESTRATION_JS = """
|
|||||||
if (opts && !isNil(opts)) {
|
if (opts && !isNil(opts)) {
|
||||||
if (opts.once || opts["once"]) o.once = true;
|
if (opts.once || opts["once"]) o.once = true;
|
||||||
}
|
}
|
||||||
el.addEventListener(event, fn, o);
|
el.addEventListener(event, function(e) {
|
||||||
|
try { fn(e); } catch (err) { console.error("[sx-ref] event handler error:", event, err); }
|
||||||
|
}, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Validation ---
|
// --- Validation ---
|
||||||
|
|||||||
@@ -373,7 +373,6 @@
|
|||||||
(when listen-target
|
(when listen-target
|
||||||
(dom-add-listener listen-target event-name
|
(dom-add-listener listen-target event-name
|
||||||
(fn (e)
|
(fn (e)
|
||||||
(log-info (str "sx:bind-event fired: " event-name " on " (dom-tag-name el)))
|
|
||||||
(let ((should-fire true))
|
(let ((should-fire true))
|
||||||
;; Changed modifier: skip if value unchanged
|
;; Changed modifier: skip if value unchanged
|
||||||
(when (get mods "changed")
|
(when (get mods "changed")
|
||||||
@@ -396,6 +395,7 @@
|
|||||||
(not (get mods "delay"))))
|
(not (get mods "delay"))))
|
||||||
(client-routed false))
|
(client-routed false))
|
||||||
(when is-get-link
|
(when is-get-link
|
||||||
|
(log-info (str "sx:route trying " (get verbInfo "url")))
|
||||||
(set! client-routed
|
(set! client-routed
|
||||||
(try-client-route (url-pathname (get verbInfo "url")))))
|
(try-client-route (url-pathname (get verbInfo "url")))))
|
||||||
(if client-routed
|
(if client-routed
|
||||||
|
|||||||
Reference in New Issue
Block a user