extensionDownloader: Use registered D-Bus error
Instead of returning ad-hoc errors, register a custom error domain and return appropriate GLib.Errors. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3159>
This commit is contained in:
parent
f38e3f4b5d
commit
f233aebe3a
@ -41,3 +41,13 @@ const notificationErrorNames = [
|
|||||||
export const NotificationErrors =
|
export const NotificationErrors =
|
||||||
registerErrorDomain('Notifications', notificationErrorNames, 'org.gtk');
|
registerErrorDomain('Notifications', notificationErrorNames, 'org.gtk');
|
||||||
export const NotificationError = createErrorEnum(notificationErrorNames);
|
export const NotificationError = createErrorEnum(notificationErrorNames);
|
||||||
|
|
||||||
|
const extensionErrorNames = [
|
||||||
|
'InfoDownloadFailed',
|
||||||
|
'DownloadFailed',
|
||||||
|
'ExtractFailed',
|
||||||
|
'EnableFailed',
|
||||||
|
];
|
||||||
|
export const ExtensionErrors =
|
||||||
|
registerErrorDomain('Extensions', extensionErrorNames);
|
||||||
|
export const ExtensionError = createErrorEnum(extensionErrorNames);
|
||||||
|
@ -13,6 +13,8 @@ import * as FileUtils from '../misc/fileUtils.js';
|
|||||||
import * as Main from './main.js';
|
import * as Main from './main.js';
|
||||||
import * as ModalDialog from './modalDialog.js';
|
import * as ModalDialog from './modalDialog.js';
|
||||||
|
|
||||||
|
import {ExtensionErrors, ExtensionError} from '../misc/dbusErrors.js';
|
||||||
|
|
||||||
Gio._promisify(Soup.Session.prototype, 'send_and_read_async');
|
Gio._promisify(Soup.Session.prototype, 'send_and_read_async');
|
||||||
Gio._promisify(Gio.OutputStream.prototype, 'write_bytes_async');
|
Gio._promisify(Gio.OutputStream.prototype, 'write_bytes_async');
|
||||||
Gio._promisify(Gio.IOStream.prototype, 'close_async');
|
Gio._promisify(Gio.IOStream.prototype, 'close_async');
|
||||||
@ -50,8 +52,9 @@ export async function installExtension(uuid, invocation) {
|
|||||||
info = JSON.parse(decoder.decode(bytes.get_data()));
|
info = JSON.parse(decoder.decode(bytes.get_data()));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Main.extensionManager.logExtensionError(uuid, e);
|
Main.extensionManager.logExtensionError(uuid, e);
|
||||||
invocation.return_dbus_error(
|
invocation.return_error_literal(
|
||||||
'org.gnome.Shell.ExtensionError', e.message);
|
ExtensionErrors, ExtensionError.INFO_DOWNLOAD_FAILED,
|
||||||
|
e.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,6 +246,18 @@ export async function checkForUpdates() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ExtractError extends Error {
|
||||||
|
get name() {
|
||||||
|
return 'ExtractError';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EnableError extends Error {
|
||||||
|
get name() {
|
||||||
|
return 'EnableError';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const InstallExtensionDialog = GObject.registerClass(
|
const InstallExtensionDialog = GObject.registerClass(
|
||||||
class InstallExtensionDialog extends ModalDialog.ModalDialog {
|
class InstallExtensionDialog extends ModalDialog.ModalDialog {
|
||||||
_init(uuid, info, invocation) {
|
_init(uuid, info, invocation) {
|
||||||
@ -293,19 +308,31 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
|
|||||||
null);
|
null);
|
||||||
checkResponse(message);
|
checkResponse(message);
|
||||||
|
|
||||||
await extractExtensionArchive(bytes, dir);
|
try {
|
||||||
|
await extractExtensionArchive(bytes, dir);
|
||||||
|
} catch (e) {
|
||||||
|
throw new ExtractError(e.message);
|
||||||
|
}
|
||||||
|
|
||||||
const extension = Main.extensionManager.createExtensionObject(
|
const extension = Main.extensionManager.createExtensionObject(
|
||||||
this._uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
|
this._uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
|
||||||
Main.extensionManager.loadExtension(extension);
|
Main.extensionManager.loadExtension(extension);
|
||||||
if (!Main.extensionManager.enableExtension(this._uuid))
|
if (!Main.extensionManager.enableExtension(this._uuid))
|
||||||
throw new Error(`Cannot enable ${this._uuid}`);
|
throw new EnableError(`Cannot enable ${this._uuid}`);
|
||||||
|
|
||||||
this._invocation.return_value(new GLib.Variant('(s)', ['successful']));
|
this._invocation.return_value(new GLib.Variant('(s)', ['successful']));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
let code;
|
||||||
|
if (e instanceof ExtractError)
|
||||||
|
code = ExtensionError.EXTRACT_FAILED;
|
||||||
|
else if (e instanceof EnableError)
|
||||||
|
code = ExtensionError.ENABLE_FAILED;
|
||||||
|
else
|
||||||
|
code = ExtensionError.DOWNLOAD_FAILED;
|
||||||
|
|
||||||
log(`Error while installing ${this._uuid}: ${e.message}`);
|
log(`Error while installing ${this._uuid}: ${e.message}`);
|
||||||
this._invocation.return_dbus_error(
|
this._invocation.return_error_literal(
|
||||||
'org.gnome.Shell.ExtensionError', e.message);
|
ExtensionErrors, code, e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user