Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

NativeFileError for error callbacks in NativeFileSystem (#2057) #2318

Merged
merged 7 commits into from
Dec 11, 2012
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
)
);
}
Expand All @@ -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);
});
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,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],
Expand Down
2 changes: 1 addition & 1 deletion src/editor/EditorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions src/file/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
)
);
}
Expand Down
73 changes: 73 additions & 0 deletions src/file/NativeFileError.js
Original file line number Diff line number Diff line change
@@ -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;
});
Loading