extensions: Consistently handle createExtensionObject() errors

The method may throw an error, for example when metadata.json is
missing or cannot be parsed, however we are currently not always
handling it.

https://bugzilla.gnome.org/show_bug.cgi?id=781728
This commit is contained in:
Florian Müllner 2017-05-17 23:51:49 +02:00
parent 8d6efde091
commit 88b1a5d3a0
2 changed files with 13 additions and 5 deletions

View File

@ -130,12 +130,14 @@ function updateExtension(uuid) {
FileUtils.recursivelyMoveDir(extensionDir, oldExtensionTmpDir); FileUtils.recursivelyMoveDir(extensionDir, oldExtensionTmpDir);
FileUtils.recursivelyMoveDir(newExtensionTmpDir, extensionDir); FileUtils.recursivelyMoveDir(newExtensionTmpDir, extensionDir);
let extension = ExtensionUtils.createExtensionObject(uuid, extensionDir, ExtensionUtils.ExtensionType.PER_USER); let extension = null;
try { try {
extension = ExtensionUtils.createExtensionObject(uuid, extensionDir, ExtensionUtils.ExtensionType.PER_USER);
ExtensionSystem.loadExtension(extension); ExtensionSystem.loadExtension(extension);
} catch(e) { } catch(e) {
ExtensionSystem.unloadExtension(extension); if (extension)
ExtensionSystem.unloadExtension(extension);
logError(e, 'Error loading extension %s'.format(uuid)); logError(e, 'Error loading extension %s'.format(uuid));
@ -242,9 +244,8 @@ const InstallExtensionDialog = new Lang.Class({
global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions); global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
} }
let extension = ExtensionUtils.createExtensionObject(uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
try { try {
let extension = ExtensionUtils.createExtensionObject(uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
ExtensionSystem.loadExtension(extension); ExtensionSystem.loadExtension(extension);
} catch(e) { } catch(e) {
uninstallExtension(uuid); uninstallExtension(uuid);

View File

@ -199,7 +199,14 @@ function reloadExtension(oldExtension) {
unloadExtension(oldExtension); unloadExtension(oldExtension);
// Now, recreate the extension and load it. // Now, recreate the extension and load it.
let newExtension = ExtensionUtils.createExtensionObject(uuid, dir, type); let newExtension;
try {
newExtension = ExtensionUtils.createExtensionObject(uuid, dir, type);
} catch(e) {
logExtensionError(uuid, e);
return;
}
loadExtension(newExtension); loadExtension(newExtension);
} }