From 93f109fbba13a67f3b8511e551346f7e5c09f0c6 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Fri, 16 Jan 2015 10:45:48 -0800 Subject: [PATCH] Add a better message for EPERM errors. --- spec/workspace-spec.coffee | 31 +++++++++++++++++++++++++++++++ src/workspace.coffee | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 810278c7a..a05125c9f 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -315,6 +315,25 @@ describe "Workspace", -> expect(notification.getMessage()).toContain 'Permission denied' expect(notification.getMessage()).toContain 'file1' + describe "when the the operation is not permitted", -> + beforeEach -> + spyOn(fs, 'openSync').andCallFake (path) -> + error = new Error("EPERM, operation not permitted '#{path}'") + error.path = path + error.code = 'EPERM' + throw error + + it "creates a notification", -> + waitsForPromise -> + workspace.open('file1') + + runs -> + expect(notificationSpy).toHaveBeenCalled() + notification = notificationSpy.mostRecentCall.args[0] + expect(notification.getType()).toBe 'warning' + expect(notification.getMessage()).toContain 'Unable to open' + expect(notification.getMessage()).toContain 'file1' + describe "when there is an unhandled error", -> beforeEach -> spyOn(fs, 'openSync').andCallFake (path) -> @@ -948,6 +967,18 @@ describe "Workspace", -> expect(addedSpy).toHaveBeenCalled() expect(addedSpy.mostRecentCall.args[0].getType()).toBe 'warning' + it "emits a warning notification when the operation is not permitted", -> + spyOn(Pane::, 'saveActiveItem').andCallFake -> + error = new Error("EPERM, operation not permitted '/Some/dir/and-a-file.js'") + error.code = 'EPERM' + error.path = '/Some/dir/and-a-file.js' + throw error + + atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy() + atom.workspace.saveActivePaneItem() + expect(addedSpy).toHaveBeenCalled() + expect(addedSpy.mostRecentCall.args[0].getType()).toBe 'warning' + it "emits a warning notification when the file cannot be saved", -> spyOn(Pane::, 'saveActiveItem').andCallFake -> throw new Error("no one knows") diff --git a/src/workspace.coffee b/src/workspace.coffee index 60b22f303..30a1d3d67 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -456,6 +456,8 @@ class Workspace extends Model 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}'") + when 'EPERM' + atom.notifications.addWarning("Unable to open '#{error.path}'", detail: error.message) else throw error return Q() @@ -625,6 +627,8 @@ class Workspace extends Model atom.notifications.addWarning("Unable to save file: #{error.message}") else if error.code is 'EACCES' and error.path? atom.notifications.addWarning("Unable to save file: Permission denied '#{error.path}'") + else if error.code is 'EPERM' and error.path? + atom.notifications.addWarning("Unable to save file '#{error.path}'", detail: error.message) else if errorMatch = /ENOTDIR, not a directory '([^']+)'/.exec(error.message) fileName = errorMatch[1] atom.notifications.addWarning("Unable to save file: A directory in the path '#{fileName}' could not be written to")