extensionDownloader: Stop returning distinct errors

Nothing looks at our made-up errors, so we can just as well return
a generic "ExtensionError".

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1940>
This commit is contained in:
Florian Müllner 2021-08-06 23:24:24 +02:00 committed by Marge Bot
parent b3bdcbcf3f
commit f16fda5ea1

View File

@ -25,9 +25,12 @@ function installExtension(uuid, invocation) {
let message = Soup.form_request_new_from_hash('GET', REPOSITORY_URL_INFO, params); let message = Soup.form_request_new_from_hash('GET', REPOSITORY_URL_INFO, params);
_httpSession.queue_message(message, () => { _httpSession.queue_message(message, () => {
if (message.status_code !== Soup.KnownStatusCode.OK) { const { statusCode } = message;
Main.extensionManager.logExtensionError(uuid, 'downloading info: %d'.format(message.status_code)); if (statusCode !== Soup.KnownStatusCode.OK) {
invocation.return_dbus_error('org.gnome.Shell.DownloadInfoError', message.status_code.toString()); const msg = 'Unexpected response: %s'
.format(Soup.Status.get_phrase(statusCode));
Main.extensionManager.logExtensionError(uuid, msg);
invocation.return_dbus_error('org.gnome.Shell.ExtensionError', msg);
return; return;
} }
@ -35,8 +38,9 @@ function installExtension(uuid, invocation) {
try { try {
info = JSON.parse(message.response_body.data); info = JSON.parse(message.response_body.data);
} catch (e) { } catch (e) {
Main.extensionManager.logExtensionError(uuid, 'parsing info: %s'.format(e.toString())); Main.extensionManager.logExtensionError(uuid, e);
invocation.return_dbus_error('org.gnome.Shell.ParseInfoError', e.toString()); invocation.return_dbus_error(
'org.gnome.Shell.ExtensionError', e.message);
return; return;
} }
@ -72,7 +76,8 @@ function uninstallExtension(uuid) {
function gotExtensionZipFile(session, message, uuid, dir, callback, errback) { function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
if (message.status_code !== Soup.KnownStatusCode.OK) { if (message.status_code !== Soup.KnownStatusCode.OK) {
errback('DownloadExtensionError', message.status_code); errback('Unexpected response: %s'
.format(Soup.Status.get_phrase(message.status_code)));
return; return;
} }
@ -80,7 +85,7 @@ function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
if (!dir.query_exists(null)) if (!dir.query_exists(null))
dir.make_directory_with_parents(null); dir.make_directory_with_parents(null);
} catch (e) { } catch (e) {
errback('CreateExtensionDirectoryError', e); errback(e.message);
return; return;
} }
@ -95,7 +100,7 @@ function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
null); null);
if (!success) { if (!success) {
errback('ExtractExtensionError'); errback('Failed to extract extension');
return; return;
} }
@ -103,7 +108,7 @@ function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
GLib.spawn_close_pid(pid); GLib.spawn_close_pid(pid);
if (status !== 0) if (status !== 0)
errback('ExtractExtensionError'); errback('Failed to extract extension');
else else
callback(); callback();
}); });
@ -124,8 +129,8 @@ function downloadExtensionUpdate(uuid) {
_httpSession.queue_message(message, session => { _httpSession.queue_message(message, session => {
gotExtensionZipFile(session, message, uuid, dir, () => { gotExtensionZipFile(session, message, uuid, dir, () => {
Main.extensionManager.notifyExtensionUpdate(uuid); Main.extensionManager.notifyExtensionUpdate(uuid);
}, (code, msg) => { }, msg => {
log('Error while downloading update for extension %s: %s (%s)'.format(uuid, code, msg)); log('Error while downloading update for extension %s: %s'.format(uuid, msg));
}); });
}); });
} }
@ -221,9 +226,9 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
[global.userdatadir, 'extensions', this._uuid])); [global.userdatadir, 'extensions', this._uuid]));
let uuid = this._uuid; let uuid = this._uuid;
let invocation = this._invocation; let invocation = this._invocation;
function errback(code, msg) { function errback(msg) {
log('Error while installing %s: %s (%s)'.format(uuid, code, msg)); log('Error while installing %s: %s'.format(uuid, msg));
invocation.return_dbus_error('org.gnome.Shell.%s'.format(code), msg || ''); invocation.return_dbus_error('org.gnome.Shell.ExtensionError', msg);
} }
function callback() { function callback() {
@ -234,7 +239,7 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
throw new Error('Cannot add %s to enabled extensions gsettings key'.format(uuid)); throw new Error('Cannot add %s to enabled extensions gsettings key'.format(uuid));
} catch (e) { } catch (e) {
uninstallExtension(uuid); uninstallExtension(uuid);
errback('LoadExtensionError', e); errback(e.message);
return; return;
} }