extensionSystem: Save extension errors per-extension
Extension developers may be confused about why their extensions aren't working: the LookingGlass isn't a very obvious place, or even which errors are theirs. To remedy this, save all errors per-UUID which allows them to be retrieved later. https://bugzilla.gnome.org/show_bug.cgi?id=654770
This commit is contained in:
parent
2466eb3132
commit
5810fcb14d
@ -41,6 +41,9 @@ Signals.addSignalMethods(_signals);
|
|||||||
const connect = Lang.bind(_signals, _signals.connect);
|
const connect = Lang.bind(_signals, _signals.connect);
|
||||||
const disconnect = Lang.bind(_signals, _signals.disconnect);
|
const disconnect = Lang.bind(_signals, _signals.disconnect);
|
||||||
|
|
||||||
|
// UUID => Array of error messages
|
||||||
|
var errors = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* versionCheck:
|
* versionCheck:
|
||||||
* @required: an array of versions we're compatible with
|
* @required: an array of versions we're compatible with
|
||||||
@ -71,13 +74,19 @@ function versionCheck(required, current) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logExtensionError(uuid, message) {
|
||||||
|
if (!errors[uuid]) errors[uuid] = [];
|
||||||
|
errors[uuid].push(message);
|
||||||
|
global.logError('Extension "%s" had error: %s'.format(uuid, message));
|
||||||
|
}
|
||||||
|
|
||||||
function loadExtension(dir, enabled, type) {
|
function loadExtension(dir, enabled, type) {
|
||||||
let info;
|
let info;
|
||||||
let baseErrorString = 'While loading extension from "' + dir.get_parse_name() + '": ';
|
let uuid = dir.get_basename();
|
||||||
|
|
||||||
let metadataFile = dir.get_child('metadata.json');
|
let metadataFile = dir.get_child('metadata.json');
|
||||||
if (!metadataFile.query_exists(null)) {
|
if (!metadataFile.query_exists(null)) {
|
||||||
global.logError(baseErrorString + 'Missing metadata.json');
|
logExtensionError(uuid, 'Missing metadata.json');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,44 +94,44 @@ function loadExtension(dir, enabled, type) {
|
|||||||
try {
|
try {
|
||||||
metadataContents = Shell.get_file_contents_utf8_sync(metadataFile.get_path());
|
metadataContents = Shell.get_file_contents_utf8_sync(metadataFile.get_path());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
global.logError(baseErrorString + 'Failed to load metadata.json: ' + e);
|
logExtensionError(uuid, 'Failed to load metadata.json: ' + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let meta;
|
let meta;
|
||||||
try {
|
try {
|
||||||
meta = JSON.parse(metadataContents);
|
meta = JSON.parse(metadataContents);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
global.logError(baseErrorString + 'Failed to parse metadata.json: ' + e);
|
logExtensionError(uuid, 'Failed to parse metadata.json: ' + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let requiredProperties = ['uuid', 'name', 'description', 'shell-version'];
|
let requiredProperties = ['uuid', 'name', 'description', 'shell-version'];
|
||||||
for (let i = 0; i < requiredProperties.length; i++) {
|
for (let i = 0; i < requiredProperties.length; i++) {
|
||||||
let prop = requiredProperties[i];
|
let prop = requiredProperties[i];
|
||||||
if (!meta[prop]) {
|
if (!meta[prop]) {
|
||||||
global.logError(baseErrorString + 'missing "' + prop + '" property in metadata.json');
|
logExtensionError(uuid, 'missing "' + prop + '" property in metadata.json');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extensions[meta.uuid] != undefined) {
|
if (extensions[uuid] != undefined) {
|
||||||
global.logError(baseErrorString + "extension already loaded");
|
logExtensionError(uuid, "extension already loaded");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encourage people to add this
|
// Encourage people to add this
|
||||||
if (!meta['url']) {
|
if (!meta['url']) {
|
||||||
global.log(baseErrorString + 'Warning: Missing "url" property in metadata.json');
|
global.log('Warning: Missing "url" property in metadata.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
let base = dir.get_basename();
|
if (uuid != meta.uuid) {
|
||||||
if (base != meta.uuid) {
|
logExtensionError(uuid, 'uuid "' + meta.uuid + '" from metadata.json does not match directory name "' + uuid + '"');
|
||||||
global.logError(baseErrorString + 'uuid "' + meta.uuid + '" from metadata.json does not match directory name "' + base + '"');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!versionCheck(meta['shell-version'], Config.PACKAGE_VERSION) ||
|
if (!versionCheck(meta['shell-version'], Config.PACKAGE_VERSION) ||
|
||||||
(meta['js-version'] && !versionCheck(meta['js-version'], Config.GJS_VERSION))) {
|
(meta['js-version'] && !versionCheck(meta['js-version'], Config.GJS_VERSION))) {
|
||||||
global.logError(baseErrorString + 'extension is not compatible with current GNOME Shell and/or GJS version');
|
logExtensionError(uuid, 'extension is not compatible with current GNOME Shell and/or GJS version');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +148,7 @@ function loadExtension(dir, enabled, type) {
|
|||||||
|
|
||||||
let extensionJs = dir.get_child('extension.js');
|
let extensionJs = dir.get_child('extension.js');
|
||||||
if (!extensionJs.query_exists(null)) {
|
if (!extensionJs.query_exists(null)) {
|
||||||
global.logError(baseErrorString + 'Missing extension.js');
|
logExtensionError(uuid, 'Missing extension.js');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let stylesheetPath = null;
|
let stylesheetPath = null;
|
||||||
@ -150,7 +159,7 @@ function loadExtension(dir, enabled, type) {
|
|||||||
try {
|
try {
|
||||||
theme.load_stylesheet(stylesheetFile.get_path());
|
theme.load_stylesheet(stylesheetFile.get_path());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
global.logError(baseErrorString + 'Stylesheet parse error: ' + e);
|
logExtensionError(uuid, 'Stylesheet parse error: ' + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,11 +171,11 @@ function loadExtension(dir, enabled, type) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (stylesheetPath != null)
|
if (stylesheetPath != null)
|
||||||
theme.unload_stylesheet(stylesheetPath);
|
theme.unload_stylesheet(stylesheetPath);
|
||||||
global.logError(baseErrorString + e);
|
logExtensionError(uuid, e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!extensionModule.main) {
|
if (!extensionModule.main) {
|
||||||
global.logError(baseErrorString + 'missing \'main\' function');
|
logExtensionError(uuid, 'missing \'main\' function');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -174,7 +183,7 @@ function loadExtension(dir, enabled, type) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (stylesheetPath != null)
|
if (stylesheetPath != null)
|
||||||
theme.unload_stylesheet(stylesheetPath);
|
theme.unload_stylesheet(stylesheetPath);
|
||||||
global.logError(baseErrorString + 'Failed to evaluate main function:' + e);
|
logExtensionError(uuid, 'Failed to evaluate init function:' + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
extensionMeta[meta.uuid].state = ExtensionState.ENABLED;
|
extensionMeta[meta.uuid].state = ExtensionState.ENABLED;
|
||||||
|
@ -20,6 +20,10 @@ const GnomeShellIface = {
|
|||||||
inSignature: 's',
|
inSignature: 's',
|
||||||
outSignature: 'a{sv}'
|
outSignature: 'a{sv}'
|
||||||
},
|
},
|
||||||
|
{ name: 'GetExtensionErrors',
|
||||||
|
inSignature: 's',
|
||||||
|
outSignature: 'as'
|
||||||
|
}
|
||||||
],
|
],
|
||||||
signals: [],
|
signals: [],
|
||||||
properties: [{ name: 'OverviewActive',
|
properties: [{ name: 'OverviewActive',
|
||||||
@ -80,6 +84,10 @@ GnomeShell.prototype = {
|
|||||||
return ExtensionSystem.extensionMeta[uuid] || {};
|
return ExtensionSystem.extensionMeta[uuid] || {};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
GetExtensionErrors: function(uuid) {
|
||||||
|
return ExtensionSystem.errors[uuid] || [];
|
||||||
|
},
|
||||||
|
|
||||||
get OverviewActive() {
|
get OverviewActive() {
|
||||||
return Main.overview.visible;
|
return Main.overview.visible;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user