From 5950b87dacf07eebbc58beb9a21781a8abc958e4 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 28 May 2019 19:01:51 +0200 Subject: [PATCH] luci-base: luci.js: make require() failures catcheable Refactor L.require() to use L.raise() instead of L.error() to signal class loading failures. This allows callers to handle class loading errors in a graceful manner. Signed-off-by: Jo-Philipp Wich --- modules/luci-base/htdocs/luci-static/resources/luci.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 6332790c7..853bbfc05 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -658,7 +658,7 @@ if (classes[name] != null) { /* Circular dependency */ if (from.indexOf(name) != -1) - L.error('DependencyError', + L.raise('DependencyError', 'Circular dependency: class "%s" depends on "%s"', name, from.join('" which depends on "')); @@ -670,7 +670,7 @@ var compileClass = function(res) { if (!res.ok) - L.error('NetworkError', + L.raise('NetworkError', 'HTTP error %d while loading class file "%s"', res.status, url); var source = res.text(), @@ -721,7 +721,7 @@ .format(args, source, res.url)); } catch (error) { - L.error('SyntaxError', '%s\n in %s:%s', + L.raise('SyntaxError', '%s\n in %s:%s', error.message, res.url, error.lineNumber || '?'); } @@ -751,9 +751,7 @@ }; /* Request class file */ - classes[name] = Request.get(url, { cache: true }) - .then(compileClass) - .catch(L.error); + classes[name] = Request.get(url, { cache: true }).then(compileClass); return classes[name]; }, -- 2.25.1