Permalink
Browse files

Merge pull request #2318 from jbalsas/filesystem-domerror

NativeFileError for error callbacks in NativeFileSystem (#2057)
  • Loading branch information...
2 parents 6e59f6d + 0fe2e71 commit 41646b8e6b206ffe04287f8756896e7085c1f2d6 @jasonsanjose jasonsanjose committed Dec 11, 2012
@@ -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);
@@ -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);
});
@@ -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],
@@ -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
@@ -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)
)
);
}
@@ -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;
+});
Oops, something went wrong.

0 comments on commit 41646b8

Please sign in to comment.