Fix #1286, Show proper error messages for OS.File errors
This commit is contained in:
parent
da2dedf7af
commit
1efe54e896
|
@ -1168,76 +1168,17 @@ Zotero.File = new function(){
|
||||||
|
|
||||||
if (e.name == 'NS_ERROR_FILE_ACCESS_DENIED' || e.name == 'NS_ERROR_FILE_IS_LOCKED'
|
if (e.name == 'NS_ERROR_FILE_ACCESS_DENIED' || e.name == 'NS_ERROR_FILE_IS_LOCKED'
|
||||||
// These show up on some Windows systems
|
// These show up on some Windows systems
|
||||||
|| e.name == 'NS_ERROR_FAILURE' || e.name == 'NS_ERROR_FILE_NOT_FOUND') {
|
|| e.name == 'NS_ERROR_FAILURE' || e.name == 'NS_ERROR_FILE_NOT_FOUND'
|
||||||
str = str + " " + Zotero.getString('file.accessError.cannotBe') + " " + opWord + ".";
|
// OS.File.Error
|
||||||
var checkFileWindows = Zotero.getString('file.accessError.message.windows');
|
|| e.becauseAccessDenied || e.becauseNoSuchFile) {
|
||||||
var checkFileOther = Zotero.getString('file.accessError.message.other');
|
|
||||||
var msg = str + "\n\n"
|
|
||||||
+ (Zotero.isWin ? checkFileWindows : checkFileOther)
|
|
||||||
+ "\n\n"
|
|
||||||
+ Zotero.getString('file.accessError.restart');
|
|
||||||
|
|
||||||
var e = new Zotero.Error(
|
|
||||||
msg,
|
|
||||||
0,
|
|
||||||
{
|
|
||||||
dialogButtonText: Zotero.getString('file.accessError.showParentDir'),
|
|
||||||
dialogButtonCallback: function () {
|
|
||||||
try {
|
|
||||||
file.parent.QueryInterface(Components.interfaces.nsILocalFile);
|
|
||||||
file.parent.reveal();
|
|
||||||
}
|
|
||||||
// Unsupported on some platforms
|
|
||||||
catch (e2) {
|
|
||||||
Zotero.launchFile(file.parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw (e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.checkPathAccessError = function (e, path, operation) {
|
|
||||||
var str = 'file.accessError.';
|
|
||||||
if (path) {
|
|
||||||
str += 'theFile'
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
str += 'aFile'
|
|
||||||
}
|
|
||||||
str += 'CannotBe';
|
|
||||||
|
|
||||||
switch (operation) {
|
|
||||||
case 'create':
|
|
||||||
str += 'Created';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'delete':
|
|
||||||
str += 'Deleted';
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
str += 'Updated';
|
|
||||||
}
|
|
||||||
str = Zotero.getString(str, path ? path : undefined);
|
|
||||||
|
|
||||||
Zotero.debug(path);
|
|
||||||
Zotero.debug(e, 1);
|
|
||||||
Components.utils.reportError(e);
|
|
||||||
|
|
||||||
// TODO: Check for specific errors?
|
|
||||||
if (e instanceof OS.File.Error) {
|
|
||||||
let checkFileWindows = Zotero.getString('file.accessError.message.windows');
|
let checkFileWindows = Zotero.getString('file.accessError.message.windows');
|
||||||
let checkFileOther = Zotero.getString('file.accessError.message.other');
|
let checkFileOther = Zotero.getString('file.accessError.message.other');
|
||||||
var msg = str + "\n\n"
|
let msg = str + "\n\n"
|
||||||
+ (Zotero.isWin ? checkFileWindows : checkFileOther)
|
+ (Zotero.isWin ? checkFileWindows : checkFileOther)
|
||||||
+ "\n\n"
|
+ "\n\n"
|
||||||
+ Zotero.getString('file.accessError.restart');
|
+ Zotero.getString('file.accessError.restart');
|
||||||
|
|
||||||
var e = new Zotero.Error(
|
e = new Zotero.Error(
|
||||||
msg,
|
msg,
|
||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
|
@ -1248,7 +1189,7 @@ Zotero.File = new function(){
|
||||||
file.parent.reveal();
|
file.parent.reveal();
|
||||||
}
|
}
|
||||||
// Unsupported on some platforms
|
// Unsupported on some platforms
|
||||||
catch (e2) {
|
catch (e) {
|
||||||
Zotero.launchFile(file.parent);
|
Zotero.launchFile(file.parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -367,7 +367,7 @@ Zotero.Sync.Storage.Local = {
|
||||||
yield OS.File.setDates(path, null, mtime);
|
yield OS.File.setDates(path, null, mtime);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Zotero.File.checkPathAccessError(e, path, 'update');
|
Zotero.File.checkFileAccessError(e, path, 'update');
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,4 +188,27 @@ describe("Zotero.File", function () {
|
||||||
assert.propertyVal(files, 'sub/b.txt', 'B');
|
assert.propertyVal(files, 'sub/b.txt', 'B');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("#checkFileAccessError()", function () {
|
||||||
|
it("should catch OS.File access-denied errors", function* () {
|
||||||
|
// We can't modify a real OS.File.Error, but we also don't do an instanceof check in
|
||||||
|
// checkFileAccessError, so just set the expected properties.
|
||||||
|
var e = {
|
||||||
|
operation: 'open',
|
||||||
|
becauseAccessDenied: true,
|
||||||
|
path: '/tmp/test'
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
Zotero.File.checkFileAccessError(e, e.path, 'create');
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
if (e instanceof Zotero.Error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
throw new Error("Error not thrown");
|
||||||
|
});
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user