Issue #1208: Fix jsonLoad in Sync's util.js to handle errors.

- `OS.Path.join` can throw, so we always need to try/catch it.
- Also do a sanity check to make sure `callback` is defined before use
This commit is contained in:
wolfbeast 2019-08-15 09:52:38 +02:00 committed by Roy Tam
commit c0204d7955

View file

@ -321,10 +321,17 @@ this.Utils = {
* could not be loaded, the first argument will be undefined.
*/
jsonLoad: Task.async(function*(filePath, that, callback) {
let path = OS.Path.join(OS.Constants.Path.profileDir, "weave", filePath + ".json");
let path;
try {
path = OS.Path.normalize(OS.Path.join(OS.Constants.Path.profileDir, "weave", filePath + ".json"));
} catch (e) {
if (that._log) {
that._log.debug("Path join error: " + e);
}
}
if (that._log) {
that._log.trace("Loading json from disk: " + filePath);
that._log.trace("Loading json from disk: " + path);
}
let json;
@ -341,8 +348,9 @@ this.Utils = {
}
}
}
callback.call(that, json);
if (callback) {
callback.call(that, json);
}
}),
/**