Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2318 from jbalsas/filesystem-domerror

NativeFileError for error callbacks in NativeFileSystem (#2057)
  • Loading branch information...
commit 41646b8e6b206ffe04287f8756896e7085c1f2d6 2 parents 6e59f6d + 0fe2e71
@jasonsanjose jasonsanjose authored
View
7 src/LiveDevelopment/LiveDevelopment.js
@@ -22,7 +22,7 @@
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
-/*global define, $, FileError, brackets, window */
+/*global define, $, brackets, window */
/**
* LiveDevelopment manages the Inspector, all Agents, and the active LiveDocument
@@ -68,6 +68,7 @@ define(function LiveDevelopment(require, exports, module) {
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
FileUtils = require("file/FileUtils"),
+ NativeFileError = require("file/NativeFileError"),
NativeApp = require("utils/NativeApp"),
PreferencesDialogs = require("preferences/PreferencesDialogs"),
ProjectManager = require("project/ProjectManager"),
@@ -558,7 +559,7 @@ define(function LiveDevelopment(require, exports, module) {
// --remote-debugging-port flag set.
NativeApp.openLiveBrowser(
url,
- err !== FileError.ERR_NOT_FOUND
+ err !== NativeFileError.ERR_NOT_FOUND
)
.done(function () {
browserStarted = true;
@@ -567,7 +568,7 @@ define(function LiveDevelopment(require, exports, module) {
var message;
_setStatus(STATUS_ERROR);
- if (err === FileError.NOT_FOUND_ERR) {
+ if (err === NativeFileError.NOT_FOUND_ERR) {
message = Strings.ERROR_CANT_FIND_CHROME;
} else {
message = StringUtils.format(Strings.ERROR_LAUNCHING_BROWSER, err);
View
12 src/document/DocumentCommandHandlers.js
@@ -154,7 +154,7 @@ define(function (require, exports, module) {
result.resolve(doc);
})
.fail(function (fileError) {
- FileUtils.showFileOpenError(fileError.code, fullPath).done(function () {
+ FileUtils.showFileOpenError(fileError.name, fullPath).done(function () {
// For performance, we do lazy checking of file existence, so it may be in working set
DocumentManager.removeFromWorkingSet(new NativeFileSystem.FileEntry(fullPath));
EditorManager.focusEditor();
@@ -365,14 +365,14 @@ define(function (require, exports, module) {
_handleNewItemInProject(true);
}
- function showSaveFileError(code, path) {
+ function showSaveFileError(name, path) {
return Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
Strings.ERROR_SAVING_FILE_TITLE,
StringUtils.format(
Strings.ERROR_SAVING_FILE,
StringUtils.htmlEscape(path),
- FileUtils.getFileErrorString(code)
+ FileUtils.getFileErrorString(name)
)
);
}
@@ -382,7 +382,7 @@ define(function (require, exports, module) {
var result = new $.Deferred();
function handleError(error, fileEntry) {
- showSaveFileError(error.code, fileEntry.fullPath)
+ showSaveFileError(error.name, fileEntry.fullPath)
.always(function () {
result.reject(error);
});
@@ -486,7 +486,7 @@ define(function (require, exports, module) {
* Reverts the Document to the current contents of its file on disk. Discards any unsaved changes
* in the Document.
* @param {Document} doc
- * @return {$.Promise} a Promise that's resolved when done, or rejected with a FileError if the
+ * @return {$.Promise} a Promise that's resolved when done, or rejected with a NativeFileError if the
* file cannot be read (after showing an error dialog to the user).
*/
function doRevert(doc) {
@@ -498,7 +498,7 @@ define(function (require, exports, module) {
result.resolve();
})
.fail(function (error) {
- FileUtils.showFileOpenError(error.code, doc.file.fullPath)
+ FileUtils.showFileOpenError(error.name, doc.file.fullPath)
.always(function () {
result.reject(error);
});
View
2  src/document/DocumentManager.js
@@ -934,7 +934,7 @@ define(function (require, exports, module) {
*
* @param {!string} fullPath
* @return {$.Promise} A promise object that will be resolved with the Document, or rejected
- * with a FileError if the file is not yet open and can't be read from disk.
+ * with a NativeFileError if the file is not yet open and can't be read from disk.
*/
function getDocumentForPath(fullPath) {
var doc = _openDocuments[fullPath],
View
2  src/editor/EditorUtils.js
@@ -23,7 +23,7 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
-/*global define, PathUtils, FileError, brackets */
+/*global define, PathUtils, brackets */
/**
* Set of utilites for working with the code editor
View
19 src/file/FileUtils.js
@@ -34,6 +34,7 @@ define(function (require, exports, module) {
require("utils/Global");
var NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
+ NativeFileError = require("file/NativeFileError"),
PerfUtils = require("utils/PerfUtils"),
Dialogs = require("widgets/Dialogs"),
Strings = require("strings"),
@@ -44,7 +45,7 @@ define(function (require, exports, module) {
/**
* Asynchronously reads a file as UTF-8 encoded text.
* @return {$.Promise} a jQuery promise that will be resolved with the
- * file's text content plus its timestamp, or rejected with a FileError if
+ * file's text content plus its timestamp, or rejected with a NativeFileError if
* the file can not be read.
*/
function readAsText(fileEntry) {
@@ -88,7 +89,7 @@ define(function (require, exports, module) {
* @param {!FileEntry} fileEntry
* @param {!string} text
* @return {$.Promise} a jQuery promise that will be resolved when
- * file writing completes, or rejected with a FileError.
+ * file writing completes, or rejected with a NativeFileError.
*/
function writeText(fileEntry, text) {
var result = new $.Deferred();
@@ -156,32 +157,32 @@ define(function (require, exports, module) {
return text.replace(findAnyEol, eolStr);
}
- function getFileErrorString(code) {
+ function getFileErrorString(name) {
// There are a few error codes that we have specific error messages for. The rest are
// displayed with a generic "(error N)" message.
var result;
- if (code === FileError.NOT_FOUND_ERR) {
+ if (name === NativeFileError.NOT_FOUND_ERR) {
result = Strings.NOT_FOUND_ERR;
- } else if (code === FileError.NOT_READABLE_ERR) {
+ } else if (name === NativeFileError.NOT_READABLE_ERR) {
result = Strings.NOT_READABLE_ERR;
- } else if (code === FileError.NO_MODIFICATION_ALLOWED_ERR) {
+ } else if (name === NativeFileError.NO_MODIFICATION_ALLOWED_ERR) {
result = Strings.NO_MODIFICATION_ALLOWED_ERR_FILE;
} else {
- result = StringUtils.format(Strings.GENERIC_ERROR, code);
+ result = StringUtils.format(Strings.GENERIC_ERROR, name);
}
return result;
}
- function showFileOpenError(code, path) {
+ function showFileOpenError(name, path) {
return Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
Strings.ERROR_OPENING_FILE_TITLE,
StringUtils.format(
Strings.ERROR_OPENING_FILE,
StringUtils.htmlEscape(path),
- getFileErrorString(code)
+ getFileErrorString(name)
)
);
}
View
73 src/file/NativeFileError.js
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50*/
+/*global define */
+
+define(function () {
+ "use strict";
+
+ /**
+ * Implementation of w3 DOMError interface
+ * http://www.w3.org/TR/2012/WD-dom-20120105/#interface-domerror
+ *
+ * NativeFileError describes possible errors occurred during NativeFileSystem
+ * operations. It is inteneded to be used in error handling through other means
+ * than exceptions.
+ * @constructor
+ * @implements {DOMError}
+ *
+ */
+ var NativeFileError = function (name) {
+
+ /**
+ * The name of the error
+ * @const
+ * @type {string}
+ */
+ Object.defineProperty(this, "name", {
+ value: name,
+ writable: false
+ });
+ };
+
+ /**
+ * Possible error name constants for NativeFileSystem operations. For details check:
+ * http://www.w3.org/TR/file-system-api/#definitions
+ * http://dev.w3.org/2009/dap/file-system/file-writer.html#definitions
+ */
+ NativeFileError.NOT_FOUND_ERR = "NotFoundError";
+ NativeFileError.SECURITY_ERR = "SecurityError";
+ NativeFileError.ABORT_ERR = "AbortError";
+ NativeFileError.NOT_READABLE_ERR = "NotReadableError";
+ NativeFileError.NO_MODIFICATION_ALLOWED_ERR = "NoModificationAllowedError";
+ NativeFileError.INVALID_STATE_ERR = "InvalidStateError";
+ NativeFileError.SYNTAX_ERR = "SyntaxError";
+ NativeFileError.INVALID_MODIFICATION_ERR = "InvalidModificationError";
+ NativeFileError.QUOTA_EXCEEDED_ERR = "QuotaExceededError";
+ NativeFileError.TYPE_MISMATCH_ERR = "TypeMismatchError";
+ NativeFileError.PATH_EXISTS_ERR = "PathExistsError";
+
+ // Define public API
+ return NativeFileError;
+});
View
120 src/file/NativeFileSystem.js
@@ -22,29 +22,14 @@
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50*/
-/*global $, define, brackets, FileError, InvalidateStateError, window */
+/*global $, define, brackets, InvalidateStateError, window */
define(function (require, exports, module) {
"use strict";
- //define FileError as currently ONLY Chrome implements the File API W3C Working Draft
- window.FileError = window.FileError || {
- NOT_FOUND_ERR: 1,
- SECURITY_ERR: 2,
- ABORT_ERR: 3,
- NOT_READABLE_ERR: 4,
- ENCODING_ERR: 5,
- NO_MODIFICATION_ALLOWED_ERR: 6,
- INVALID_STATE_ERR: 7,
- SYNTAX_ERR: 8,
- INVALID_MODIFICATION_ERR: 9,
- QUOTA_EXCEEDED_ERR: 10,
- TYPE_MISMATCH_ERR: 11,
- PATH_EXISTS_ERR: 12
- };
-
- var Async = require("utils/Async");
-
+ var Async = require("utils/Async"),
+ NativeFileError = require("file/NativeFileError");
+
/*
* Generally NativeFileSystem mimics the File API working draft
* http://www.w3.org/TR/file-system-api/. The w3 entry point
@@ -74,7 +59,7 @@ define(function (require, exports, module) {
* @param {string} initialPath
* @param {Array.<string>} fileTypes
* @param {!function(Array.<string>)} successCallback
- * @param {!function(number)} errorCallback (TODO #2057: should this pass a FileError?)
+ * @param {!function(DOMError)} errorCallback
* @constructor
*/
showOpenDialog: function (allowMultipleSelection,
@@ -98,7 +83,7 @@ define(function (require, exports, module) {
if (!err) {
successCallback(data);
} else if (errorCallback) {
- errorCallback(NativeFileSystem._nativeToFileError(err));
+ errorCallback(new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(err)));
}
}
);
@@ -108,14 +93,14 @@ define(function (require, exports, module) {
*
* @param {!string} path
* @param {!function(FileSystem)} successCallback
- * @param {!function(FileError)} errorCallback (TODO #2057: should pass a DOMError)
+ * @param {!function(DOMError)} errorCallback
*/
requestNativeFileSystem: function (path, successCallback, errorCallback) {
brackets.fs.stat(path, function (err, data) {
if (!err) {
successCallback(new NativeFileSystem.FileSystem(path));
} else if (errorCallback) {
- errorCallback(NativeFileSystem._nativeToFileError(err));
+ errorCallback(new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(err)));
}
});
},
@@ -146,46 +131,46 @@ define(function (require, exports, module) {
},
/**
- * Converts a brackets.fs.ERR_* error code to a FileError.* error code
- * @param {number} nativeErr
- * @return {number}
+ * Converts a brackets.fs.ERR_* error code to a NativeFileError.* error name
+ * @param {!number} fsErr A brackets.fs error code
+ * @return {string} An error name out of the possible NativeFileError.* names
*/
- _nativeToFileError: function (nativeErr) {
+ _fsErrorToDOMErrorName: function (fsErr) {
var error;
- switch (nativeErr) {
+ switch (fsErr) {
// We map ERR_UNKNOWN and ERR_INVALID_PARAMS to SECURITY_ERR,
// since there aren't specific mappings for these.
case brackets.fs.ERR_UNKNOWN:
case brackets.fs.ERR_INVALID_PARAMS:
- error = FileError.SECURITY_ERR;
+ error = NativeFileError.SECURITY_ERR;
break;
case brackets.fs.ERR_NOT_FOUND:
- error = FileError.NOT_FOUND_ERR;
+ error = NativeFileError.NOT_FOUND_ERR;
break;
case brackets.fs.ERR_CANT_READ:
- error = FileError.NOT_READABLE_ERR;
+ error = NativeFileError.NOT_READABLE_ERR;
break;
- // It might seem like you should use FileError.ENCODING_ERR for this,
+ // It might seem like you should use NativeFileError.ENCODING_ERR for this,
// but according to the spec that's for malformed URLs.
case brackets.fs.ERR_UNSUPPORTED_ENCODING:
- error = FileError.SECURITY_ERR;
+ error = NativeFileError.SECURITY_ERR;
break;
case brackets.fs.ERR_CANT_WRITE:
- error = FileError.NO_MODIFICATION_ALLOWED_ERR;
+ error = NativeFileError.NO_MODIFICATION_ALLOWED_ERR;
break;
case brackets.fs.ERR_OUT_OF_SPACE:
- error = FileError.QUOTA_EXCEEDED_ERR;
+ error = NativeFileError.QUOTA_EXCEEDED_ERR;
break;
case brackets.fs.PATH_EXISTS_ERR:
- error = FileError.PATH_EXISTS_ERR;
+ error = NativeFileError.PATH_EXISTS_ERR;
break;
default:
// The HTML file spec says SECURITY_ERR is a catch-all to be used in situations
// not covered by other error codes.
- error = FileError.SECURITY_ERR;
+ error = NativeFileError.SECURITY_ERR;
}
- return new NativeFileSystem.FileError(error);
+ return error;
}
};
@@ -291,7 +276,7 @@ define(function (require, exports, module) {
/**
* @param {!function(Metadata)} successCallBack
- * @param {!function(number)} errorCallback (TODO #2057: should pass a FileError)
+ * @param {!function(DOMError)} errorCallback
*/
NativeFileSystem.Entry.prototype.getMetadata = function (successCallBack, errorCallback) {
brackets.fs.stat(this.fullPath, function (err, stat) {
@@ -299,7 +284,7 @@ define(function (require, exports, module) {
var metadata = new NativeFileSystem.Metadata(stat.mtime);
successCallBack(metadata);
} else {
- errorCallback(NativeFileSystem._nativeToFileError(err));
+ errorCallback(new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(err)));
}
});
};
@@ -334,7 +319,7 @@ define(function (require, exports, module) {
* Creates a new FileWriter associated with the file that this FileEntry represents.
*
* @param {!function(FileWriter)} successCallback
- * @param {!function(number)} errorCallback (TODO #2057: should pass a FileError)
+ * @param {!function(DOMError)} errorCallback
*/
NativeFileSystem.FileEntry.prototype.createWriter = function (successCallback, errorCallback) {
var fileEntry = this;
@@ -379,7 +364,7 @@ define(function (require, exports, module) {
brackets.fs.writeFile(fileEntry.fullPath, data, _FSEncodings.UTF8, function (err) {
if ((err !== brackets.fs.NO_ERROR) && self.onerror) {
- var fileError = NativeFileSystem._nativeToFileError(err);
+ var fileError = new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(err));
// TODO (issue #241): set readonly FileSaver.error attribute
// self._error = fileError;
@@ -436,7 +421,7 @@ define(function (require, exports, module) {
result.done(function () {
if (fileWriter._err && (errorCallback !== undefined)) {
- errorCallback(NativeFileSystem._nativeToFileError(fileWriter._err));
+ errorCallback(new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(fileWriter._err)));
} else if (successCallback !== undefined) {
successCallback(fileWriter);
}
@@ -447,7 +432,7 @@ define(function (require, exports, module) {
* Obtains the File objecte for a FileEntry object
*
* @param {!function(File)} successCallback
- * @param {!function(FileError)} errorCallback
+ * @param {!function(DOMError)} errorCallback
*/
NativeFileSystem.FileEntry.prototype.file = function (successCallback, errorCallback) {
var newFile = new NativeFileSystem.File(this);
@@ -532,7 +517,7 @@ define(function (require, exports, module) {
// TODO (issue #241): Terminate any steps having to do with writing a file.
// Set the error attribute to a FileError object with the code ABORT_ERR.
- this._error = new NativeFileSystem.FileError(FileError.ABORT_ERR);
+ this._error = new NativeFileError(NativeFileError.ABORT_ERR);
// Set readyState to DONE.
this._readyState = NativeFileSystem.FileSaver.DONE;
@@ -569,7 +554,7 @@ define(function (require, exports, module) {
* @param {!string} path
* @param {!{create:?boolean, exclusive:?boolean}} options
* @param {!function(DirectoryEntry)} successCallback
- * @param {!function(FileError|number)} errorCallback (TODO #2057: should consistently pass a FileError)
+ * @param {!function(DOMError)} errorCallback
*/
NativeFileSystem.DirectoryEntry.prototype.getDirectory = function (path, options, successCallback, errorCallback) {
var directoryFullPath = path,
@@ -599,7 +584,7 @@ define(function (require, exports, module) {
var createDirectoryError = function (err) {
if (errorCallback) {
- errorCallback(NativeFileSystem._nativeToFileError(err));
+ errorCallback(new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(err)));
}
};
@@ -611,7 +596,7 @@ define(function (require, exports, module) {
// throw error if the file the path is not a directory
if (!stats.isDirectory()) {
if (errorCallback) {
- errorCallback(new NativeFileSystem.FileError(FileError.TYPE_MISMATCH_ERR));
+ errorCallback(new NativeFileError(NativeFileError.TYPE_MISMATCH_ERR));
}
return;
@@ -620,7 +605,7 @@ define(function (require, exports, module) {
// throw error if the file exists but create is exclusive
if (options.create && options.exclusive) {
if (errorCallback) {
- errorCallback(new NativeFileSystem.FileError(FileError.PATH_EXISTS_ERR));
+ errorCallback(new NativeFileError(NativeFileError.PATH_EXISTS_ERR));
}
return;
@@ -648,7 +633,7 @@ define(function (require, exports, module) {
// throw error if file not found and the create == false
if (errorCallback) {
- errorCallback(new NativeFileSystem.FileError(FileError.NOT_FOUND_ERR));
+ errorCallback(new NativeFileError(NativeFileError.NOT_FOUND_ERR));
}
} else {
// all other brackets.fs.stat() errors
@@ -678,7 +663,7 @@ define(function (require, exports, module) {
* exist.
* @param {!{create:?boolean, exclusive:?boolean}} options
* @param {!function(FileEntry)} successCallback
- * @param {!function(FileError|number)} errorCallback (TODO #2057: should consistently pass a FileError)
+ * @param {!function(DOMError} errorCallback
*/
NativeFileSystem.DirectoryEntry.prototype.getFile = function (path, options, successCallback, errorCallback) {
var fileFullPath = path,
@@ -708,7 +693,7 @@ define(function (require, exports, module) {
var createFileError = function (err) {
if (errorCallback) {
- errorCallback(NativeFileSystem._nativeToFileError(err));
+ errorCallback(new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(err)));
}
};
@@ -720,7 +705,7 @@ define(function (require, exports, module) {
// throw error if the file the path is a directory
if (stats.isDirectory()) {
if (errorCallback) {
- errorCallback(new NativeFileSystem.FileError(FileError.TYPE_MISMATCH_ERR));
+ errorCallback(new NativeFileError(NativeFileError.TYPE_MISMATCH_ERR));
}
return;
@@ -729,7 +714,7 @@ define(function (require, exports, module) {
// throw error if the file exists but create is exclusive
if (options.create && options.exclusive) {
if (errorCallback) {
- errorCallback(new NativeFileSystem.FileError(FileError.PATH_EXISTS_ERR));
+ errorCallback(new NativeFileError(NativeFileError.PATH_EXISTS_ERR));
}
return;
@@ -756,7 +741,7 @@ define(function (require, exports, module) {
// throw error if file not found and the create == false
if (errorCallback) {
- errorCallback(new NativeFileSystem.FileError(FileError.NOT_FOUND_ERR));
+ errorCallback(new NativeFileError(NativeFileError.NOT_FOUND_ERR));
}
} else {
// all other brackets.fs.stat() errors
@@ -774,7 +759,7 @@ define(function (require, exports, module) {
/** readEntries
*
* @param {!function(Array.<Entry>)} successCallback
- * @param {!function(FileError|number)} errorCallback (TODO #2057: should consistently pass a FileError)
+ * @param {!function(DOMError} errorCallback
* @returns {Array.<Entry>}
*/
NativeFileSystem.DirectoryReader.prototype.readEntries = function (successCallback, errorCallback) {
@@ -809,7 +794,7 @@ define(function (require, exports, module) {
}
deferred.resolve();
} else {
- lastError = NativeFileSystem._nativeToFileError(statErr);
+ lastError = new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(statErr));
deferred.reject(lastError);
}
});
@@ -838,7 +823,7 @@ define(function (require, exports, module) {
if (err === Async.ERROR_TIMEOUT) {
// SECURITY_ERR is the HTML5 File catch-all error, and there isn't anything
// more fitting for a timeout.
- err = new NativeFileSystem.FileError(FileError.SECURITY_ERR);
+ err = new NativeFileError(NativeFileError.SECURITY_ERR);
} else {
err = lastError;
}
@@ -850,7 +835,7 @@ define(function (require, exports, module) {
);
} else { // There was an error reading the initial directory.
- errorCallback(NativeFileSystem._nativeToFileError(err));
+ errorCallback(new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(err)));
}
});
};
@@ -940,7 +925,7 @@ define(function (require, exports, module) {
// The target for this event is the FileReader and the data/err result is stored in the FileReader
fakeEvent.target = self;
self.result = data;
- self.error = NativeFileSystem._nativeToFileError(err);
+ self.error = new NativeFileError(NativeFileSystem._fsErrorToDOMErrorName(err));
if (err) {
self.readyState = self.DONE;
@@ -1041,21 +1026,6 @@ define(function (require, exports, module) {
});
};
- /** class: FileError
- *
- * Implementation of HTML file API error code return class. Note that we don't
- * actually define the error codes here--we rely on the browser's built-in FileError
- * class's constants. In other words, external clients of this API should always
- * use FileError.<constant-name>, not NativeFileSystem.FileError.<constant-name>.
- *
- * @constructor
- * @param {number} code The error code to return with this FileError. Must be
- * one of the codes defined in the FileError class.
- */
- NativeFileSystem.FileError = function (code) {
- this.code = code || 0;
- };
-
// Define public API
exports.NativeFileSystem = NativeFileSystem;
});
View
17 src/project/FileSyncManager.js
@@ -23,7 +23,7 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
-/*global define, $, brackets, FileError */
+/*global define, $, brackets */
/**
* FileSyncManager is a set of utilities to help track external modifications to the files and folders
@@ -49,7 +49,8 @@ define(function (require, exports, module) {
Dialogs = require("widgets/Dialogs"),
Strings = require("strings"),
StringUtils = require("utils/StringUtils"),
- FileUtils = require("file/FileUtils");
+ FileUtils = require("file/FileUtils"),
+ NativeFileError = require("file/NativeFileError");
/**
@@ -112,7 +113,7 @@ define(function (require, exports, module) {
},
function (error) {
// File has been deleted externally
- if (error.code === FileError.NOT_FOUND_ERR) {
+ if (error.name === NativeFileError.NOT_FOUND_ERR) {
if (doc.isDirty) {
deleteConflicts.push(doc);
} else {
@@ -121,7 +122,7 @@ define(function (require, exports, module) {
result.resolve();
} else {
// Some other error fetching metadata: treat as a real error
- console.log("Error checking modification status of " + doc.file.fullPath, error.code);
+ console.log("Error checking modification status of " + doc.file.fullPath, error.name);
result.reject();
}
}
@@ -154,12 +155,12 @@ define(function (require, exports, module) {
},
function (error) {
// File has been deleted externally
- if (error.code === FileError.NOT_FOUND_ERR) {
+ if (error.name === NativeFileError.NOT_FOUND_ERR) {
DocumentManager.notifyFileDeleted(file);
result.resolve();
} else {
// Some other error fetching metadata: treat as a real error
- console.log("Error checking for deletion of " + file.fullPath, error.code);
+ console.log("Error checking for deletion of " + file.fullPath, error.name);
result.reject();
}
}
@@ -187,7 +188,7 @@ define(function (require, exports, module) {
doc.refreshText(text, readTimestamp);
});
promise.fail(function (error) {
- console.log("Error reloading contents of " + doc.file.fullPath, error.code);
+ console.log("Error reloading contents of " + doc.file.fullPath, error.name);
});
return promise;
}
@@ -215,7 +216,7 @@ define(function (require, exports, module) {
StringUtils.format(
Strings.ERROR_RELOADING_FILE,
StringUtils.htmlEscape(doc.file.fullPath),
- FileUtils.getFileErrorString(error.code)
+ FileUtils.getFileErrorString(error.name)
)
);
}
View
15 src/project/ProjectManager.js
@@ -63,6 +63,7 @@ define(function (require, exports, module) {
ViewUtils = require("utils/ViewUtils"),
CollectionUtils = require("utils/CollectionUtils"),
FileUtils = require("file/FileUtils"),
+ NativeFileError = require("file/NativeFileError"),
Urls = require("i18n!nls/urls"),
KeyEvent = require("utils/KeyEvent");
@@ -655,7 +656,7 @@ define(function (require, exports, module) {
Strings.ERROR_LOADING_PROJECT,
StringUtils.format(Strings.READ_DIRECTORY_ENTRIES_ERROR,
StringUtils.htmlEscape(dirEntry.fullPath),
- error.code)
+ error.name)
);
}
);
@@ -789,7 +790,7 @@ define(function (require, exports, module) {
StringUtils.format(
Strings.REQUEST_NATIVE_FILE_SYSTEM_ERROR,
StringUtils.htmlEscape(rootPath),
- error.code
+ error.name
)
).done(function () {
// The project folder stored in preference doesn't exist, so load the default
@@ -928,7 +929,7 @@ define(function (require, exports, module) {
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
Strings.ERROR_LOADING_PROJECT,
- StringUtils.format(Strings.OPEN_DIALOG_ERROR, error.code)
+ StringUtils.format(Strings.OPEN_DIALOG_ERROR, error.name)
);
result.reject();
}
@@ -1079,8 +1080,8 @@ define(function (require, exports, module) {
};
var errorCallback = function (error) {
- if ((error.code === FileError.PATH_EXISTS_ERR)
- || (error.code === FileError.TYPE_MISMATCH_ERR)) {
+ if ((error.name === NativeFileError.PATH_EXISTS_ERR)
+ || (error.name === NativeFileError.TYPE_MISMATCH_ERR)) {
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
Strings.INVALID_FILENAME_TITLE,
@@ -1088,9 +1089,9 @@ define(function (require, exports, module) {
StringUtils.htmlEscape(data.rslt.name))
);
} else {
- var errString = error.code === FileError.NO_MODIFICATION_ALLOWED_ERR ?
+ var errString = error.name === NativeFileError.NO_MODIFICATION_ALLOWED_ERR ?
Strings.NO_MODIFICATION_ALLOWED_ERR :
- StringUtils.format(Strings.GENERIC_ERROR, error.code);
+ StringUtils.format(Strings.GENERIC_ERROR, error.name);
var errMsg = StringUtils.format(Strings.ERROR_CREATING_FILE,
StringUtils.htmlEscape(data.rslt.name),
View
23 test/spec/NativeFileSystem-test.js
@@ -32,6 +32,7 @@ define(function (require, exports, module) {
// Load dependent modules
var NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
+ NativeFileError = require("file/NativeFileError"),
SpecRunnerUtils = require("spec/SpecRunnerUtils");
var Encodings = NativeFileSystem.Encodings;
@@ -131,7 +132,7 @@ define(function (require, exports, module) {
});
runs(function () {
- expect(error.code).toBe(FileError.NOT_FOUND_ERR);
+ expect(error.name).toBe(NativeFileError.NOT_FOUND_ERR);
});
});
@@ -155,7 +156,7 @@ define(function (require, exports, module) {
});
runs(function () {
- expect(error.code).toBe(FileError.SECURITY_ERR);
+ expect(error.name).toBe(NativeFileError.SECURITY_ERR);
});
});
@@ -286,7 +287,7 @@ define(function (require, exports, module) {
expect(readComplete).toBe(true);
expect(statCalled).toBe(true);
expect(gotError).toBe(true);
- expect(theError.code).toBe(FileError.SECURITY_ERR);
+ expect(theError.name).toBe(NativeFileError.SECURITY_ERR);
});
});
});
@@ -327,7 +328,7 @@ define(function (require, exports, module) {
it("should return an error if the file is not found", function () {
var deferred = new $.Deferred(),
- errorCode;
+ errorName;
runs(function () {
var fileEntry = new NativeFileSystem.FileEntry(this.path + "/idontexist");
@@ -337,7 +338,7 @@ define(function (require, exports, module) {
deferred.resolve();
};
reader.onerror = function (event) {
- errorCode = event.target.error.code;
+ errorName = event.target.error.name;
deferred.reject();
};
reader.readAsText(file, Encodings.UTF8);
@@ -347,7 +348,7 @@ define(function (require, exports, module) {
});
runs(function () {
- expect(errorCode).toBe(FileError.NOT_FOUND_ERR);
+ expect(errorName).toBe(NativeFileError.NOT_FOUND_ERR);
});
});
@@ -529,7 +530,7 @@ define(function (require, exports, module) {
// fileEntry is null on error
runs(function () {
expect(fileEntry).toBe(null);
- expect(error.code).toBe(FileError.NOT_FOUND_ERR);
+ expect(error.name).toBe(NativeFileError.NOT_FOUND_ERR);
});
});
@@ -560,7 +561,7 @@ define(function (require, exports, module) {
expect(fileEntry).toBe(null);
// errorCallback should be called with PATH_EXISTS_ERR
- expect(error.code).toEqual(FileError.PATH_EXISTS_ERR);
+ expect(error.name).toEqual(NativeFileError.PATH_EXISTS_ERR);
});
});
@@ -591,7 +592,7 @@ define(function (require, exports, module) {
expect(fileEntry).toBe(null);
// errorCallback should be called with TYPE_MISMATCH_ERR
- expect(error.code).toEqual(FileError.TYPE_MISMATCH_ERR);
+ expect(error.name).toEqual(NativeFileError.TYPE_MISMATCH_ERR);
});
});
@@ -733,7 +734,7 @@ define(function (require, exports, module) {
runs(function () {
expect(complete).toBeFalsy();
- expect(error.code).toBe(FileError.NOT_READABLE_ERR);
+ expect(error.name).toBe(NativeFileError.NOT_READABLE_ERR);
});
});
@@ -768,7 +769,7 @@ define(function (require, exports, module) {
function () {
return writeComplete
&& error
- && (error.code === FileError.NO_MODIFICATION_ALLOWED_ERR);
+ && (error.name === NativeFileError.NO_MODIFICATION_ALLOWED_ERR);
},
1000
);
Please sign in to comment.
Something went wrong with that request. Please try again.