mirror of
https://github.com/openwrt/luci.git
synced 2025-12-21 21:24:35 +04:00
luci-app-attendedsysupgrade: do major cleanup of error handler
Extract and isolate the forum-specific constants and formats to a location that is easily modified. Factor out a lot of common code and simply make everything much cleaner and more readable. Output to the "Request Data" block was augmented to contain the system board info, and was reordered to put more important data earlier in the output. Also fix a potential bug in construction of the error html, where the final step was coercing everything to a string prematurely. Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com>
This commit is contained in:
committed by
Paul Donald
parent
74d2aad3da
commit
cf868f4398
@@ -9,6 +9,32 @@
|
|||||||
'require dom';
|
'require dom';
|
||||||
'require fs';
|
'require fs';
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------
|
||||||
|
* This section should be sufficient to isolate the changes that any forked
|
||||||
|
* versions need to change with a custom support url.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const support_url = 'https://forum.openwrt.org/t/luci-attended-sysupgrade-support-thread/230552';
|
||||||
|
const support_link = E('a', { href: support_url }, _('this forum thread'));
|
||||||
|
|
||||||
|
function detailsBlock(title, content, pre) {
|
||||||
|
/* Formatter for discourse-based forum "details" block.
|
||||||
|
*
|
||||||
|
* If the above support_url is changed to github, say, then you'd
|
||||||
|
* probably need to get rid of the '[details...]' syntax.
|
||||||
|
*/
|
||||||
|
return ! content ? '' : ''.concat(
|
||||||
|
'[details="', title, '"]\n',
|
||||||
|
pre ? '```\n' : '',
|
||||||
|
content, '\n',
|
||||||
|
pre ? '```\n' : '',
|
||||||
|
'[/details]\n',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const callPackagelist = rpc.declare({
|
const callPackagelist = rpc.declare({
|
||||||
object: 'rpc-sys',
|
object: 'rpc-sys',
|
||||||
method: 'packagelist',
|
method: 'packagelist',
|
||||||
@@ -256,95 +282,69 @@ return view.extend({
|
|||||||
sha256_unsigned: this.sha256_unsigned,
|
sha256_unsigned: this.sha256_unsigned,
|
||||||
...firmware
|
...firmware
|
||||||
};
|
};
|
||||||
|
const request_str = JSON.stringify(request_data, null, 4);
|
||||||
let body = [
|
let body = [
|
||||||
E('p', {}, [
|
E('p', {}, [
|
||||||
_('First check '),
|
_('First, check'), ' ',
|
||||||
E(
|
support_link,
|
||||||
'a',
|
_('. If you don\'t find a solution there, then report all of the information below.')
|
||||||
{ href: 'https://forum.openwrt.org/t/luci-attended-sysupgrade-support-thread/230552' },
|
|
||||||
_('this forum thread')
|
|
||||||
),
|
|
||||||
_('. If you don\'t find a solution there, report all of the information below.')
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
E(
|
E(
|
||||||
'button',
|
'button',
|
||||||
{
|
{
|
||||||
class: 'btn cbi-button cbi-button-positive important',
|
class: 'btn cbi-button cbi-button-positive important',
|
||||||
|
style: 'margin-bottom: 1em; padding: 0.2em',
|
||||||
click: ui.createHandlerFn(this, function () {
|
click: ui.createHandlerFn(this, function () {
|
||||||
|
var text = ''.concat(
|
||||||
// No translations in here as it's intended for the forum.
|
// No translations in here as it's intended for the forum.
|
||||||
var text =
|
'Server response: %s\n\n'.format(response.detail),
|
||||||
'Server response: %s'.format(response.detail)
|
detailsBlock('Request Data', request_str, true),
|
||||||
+ '\n\n'
|
detailsBlock('STDOUT', response.stdout, true),
|
||||||
+ '`--version-to %s --device %s:%s`'.format(
|
detailsBlock('STDERR', response.stderr, true),
|
||||||
request_data.version,
|
);
|
||||||
request_data.target,
|
|
||||||
request_data.profile,
|
|
||||||
)
|
|
||||||
+ '\n\n'
|
|
||||||
+ '[details="Request Data"]\n'
|
|
||||||
+ '```\n'
|
|
||||||
+ JSON.stringify({ ...request_data }, null, 4) + '\n'
|
|
||||||
+ '```\n'
|
|
||||||
+ '[/details]\n'
|
|
||||||
;
|
|
||||||
if (response.stdout) {
|
|
||||||
text = text +
|
|
||||||
'[details="STDOUT"]\n'
|
|
||||||
+ '```\n'
|
|
||||||
+ response.stdout + '\n'
|
|
||||||
+ '```\n'
|
|
||||||
+ '[/details]\n'
|
|
||||||
;
|
|
||||||
}
|
|
||||||
if (response.stderr) {
|
|
||||||
text = text +
|
|
||||||
'[details="STDERR"]\n'
|
|
||||||
+ '```\n'
|
|
||||||
+ response.stderr + '\n'
|
|
||||||
+ '```\n'
|
|
||||||
+ '[/details]\n'
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
navigator.clipboard.writeText(text);
|
navigator.clipboard.writeText(text);
|
||||||
|
|
||||||
ui.showModal(_('Data copied!'), [
|
ui.showModal(_('Data copied!'), [
|
||||||
E('p', {}, [
|
E('p', [
|
||||||
_('Paste the contents of the clipboard to '),
|
_('Paste the contents of the clipboard to'), ' ',
|
||||||
E(
|
support_link,
|
||||||
'a',
|
'.',
|
||||||
{ href: 'https://forum.openwrt.org/t/luci-attended-sysupgrade-support-thread/230552' },
|
|
||||||
_('this forum thread')
|
|
||||||
),
|
|
||||||
]),
|
]),
|
||||||
E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
|
|
||||||
]);
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
_('Copy error data to clipboard')
|
|
||||||
),
|
|
||||||
|
|
||||||
E('p', {}, _('Server response: %s').format(response.detail)),
|
|
||||||
E('p', {}, _('Request Data:')),
|
|
||||||
E('pre', {}, JSON.stringify({ ...request_data }, null, 4)),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (response.stdout) {
|
|
||||||
body.push(E('b', {}, 'STDOUT:'));
|
|
||||||
body.push(E('pre', {}, response.stdout));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.stderr) {
|
|
||||||
body.push(E('b', {}, 'STDERR:'));
|
|
||||||
body.push(E('pre', {}, response.stderr));
|
|
||||||
}
|
|
||||||
|
|
||||||
body = body.concat([
|
|
||||||
E('div', { class: 'right' }, [
|
E('div', { class: 'right' }, [
|
||||||
E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
|
E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
_('Copy error data to clipboard...')
|
||||||
|
),
|
||||||
|
|
||||||
|
E('p', _('Server response: %s').format(response.detail)),
|
||||||
|
E('p', _('Request Data:')),
|
||||||
|
E('pre', {}, request_str),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (response.stdout) {
|
||||||
|
body.push(
|
||||||
|
E('b', 'STDOUT:'),
|
||||||
|
E('pre', response.stdout),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.stderr) {
|
||||||
|
body.push(
|
||||||
|
E('b', 'STDERR:'),
|
||||||
|
E('pre', response.stderr),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
body.push(
|
||||||
|
E('div', { class: 'right' }, [
|
||||||
|
E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
ui.showModal(_('Error building the firmware image'), body);
|
ui.showModal(_('Error building the firmware image'), body);
|
||||||
},
|
},
|
||||||
@@ -692,12 +692,13 @@ return view.extend({
|
|||||||
uci.load('attendedsysupgrade'),
|
uci.load('attendedsysupgrade'),
|
||||||
]);
|
]);
|
||||||
const data = {
|
const data = {
|
||||||
|
system_board: promises[1],
|
||||||
|
advanced_mode: uci.get_first('attendedsysupgrade', 'client', 'advanced_mode') || 0,
|
||||||
url: uci.get_first('attendedsysupgrade', 'server', 'url').replace(/\/+$/, ''),
|
url: uci.get_first('attendedsysupgrade', 'server', 'url').replace(/\/+$/, ''),
|
||||||
branch: get_branch(promises[1].release.version),
|
branch: get_branch(promises[1].release.version),
|
||||||
revision: promises[1].release.revision,
|
revision: promises[1].release.revision,
|
||||||
efi: promises[2],
|
efi: promises[2],
|
||||||
advanced_mode: uci.get_first('attendedsysupgrade', 'client', 'advanced_mode') || 0,
|
rebuilder: uci.get_first('attendedsysupgrade', 'server', 'rebuilder'),
|
||||||
rebuilder: uci.get_first('attendedsysupgrade', 'server', 'rebuilder')
|
|
||||||
};
|
};
|
||||||
const firmware = {
|
const firmware = {
|
||||||
client: 'luci/' + promises[0].packages['luci-app-attendedsysupgrade'],
|
client: 'luci/' + promises[0].packages['luci-app-attendedsysupgrade'],
|
||||||
|
|||||||
Reference in New Issue
Block a user