diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 382a2eb30..810278c7a 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -287,16 +287,14 @@ describe "Workspace", -> expect(notification.getMessage()).toContain '< 2MB' describe "when a file does not exist", -> - it "creates a notification", -> + it "creates an empty buffer for the specified path", -> waitsForPromise -> workspace.open('not-a-file.md') runs -> - expect(notificationSpy).toHaveBeenCalled() - notification = notificationSpy.mostRecentCall.args[0] - expect(notification.getType()).toBe 'warning' - expect(notification.getMessage()).toContain 'No such file' - expect(notification.getMessage()).toContain 'not-a-file.md' + editor = workspace.getActiveTextEditor() + expect(notificationSpy).not.toHaveBeenCalled() + expect(editor.getPath()).toContain 'not-a-file.md' describe "when the user does not have access to the file", -> beforeEach -> diff --git a/src/project.coffee b/src/project.coffee index 7274c94f2..0c2496ca6 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -218,9 +218,12 @@ class Project extends Model filePath = @resolvePath(filePath) if filePath? - # Make sure we have permissions - fileDescriptor = fs.openSync(filePath, 'r+') - fs.closeSync(fileDescriptor) + try + fileDescriptor = fs.openSync(filePath, 'r+') + fs.closeSync(fileDescriptor) + catch error + # allow ENOENT errors to create an editor for paths that dont exist + throw error unless error.code is 'ENOENT' @bufferForPath(filePath).then (buffer) => @buildEditorForBuffer(buffer, options) diff --git a/src/workspace.coffee b/src/workspace.coffee index 4d4263820..60b22f303 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -451,14 +451,13 @@ class Workspace extends Model try item ?= atom.project.open(uri, options) catch error - if error.code is 'EFILETOOLARGE' - atom.notifications.addWarning("#{error.message} Large file support is being tracked at [atom/atom#307](https://github.com/atom/atom/issues/307).") - else if error.code is 'ENOENT' and error.path? - atom.notifications.addWarning("No such file '#{error.path}'") - else if error.code is 'EACCES' and error.path? - atom.notifications.addWarning("Permission denied '#{error.path}'") - else - throw error + switch error.code + when 'EFILETOOLARGE' + atom.notifications.addWarning("#{error.message} Large file support is being tracked at [atom/atom#307](https://github.com/atom/atom/issues/307).") + when 'EACCES' + atom.notifications.addWarning("Permission denied '#{error.path}'") + else + throw error return Q() Q(item)