Add a better message for EPERM errors.

This commit is contained in:
Ben Ogle
2015-01-16 10:45:48 -08:00
parent 97a55ba8c0
commit 93f109fbba
2 changed files with 35 additions and 0 deletions

View File

@@ -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")

View File

@@ -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")