From d5e04e883eb110177cd1a5170e37f52a24080803 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 7 Jan 2015 17:12:55 -0800 Subject: [PATCH] Use the error.code and path in the error --- spec/workspace-view-spec.coffee | 5 ++++- src/workspace.coffee | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/workspace-view-spec.coffee b/spec/workspace-view-spec.coffee index ade0dcc4d..e2065a661 100644 --- a/spec/workspace-view-spec.coffee +++ b/spec/workspace-view-spec.coffee @@ -318,7 +318,10 @@ describe "WorkspaceView", -> it "emits a warning notification when the user does not have permission", -> spyOn(Pane::, 'saveActiveItem').andCallFake -> - throw new Error("EACCES, permission denied '/Some/dir/and-a-file.js'") + error = new Error("EACCES, permission denied '/Some/dir/and-a-file.js'") + error.code = 'EACCES' + error.path = '/Some/dir/and-a-file.js' + throw error atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy() atom.workspace.saveActivePaneItem() diff --git a/src/workspace.coffee b/src/workspace.coffee index 4efd1d6e6..3c11c7d27 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -624,8 +624,8 @@ class Workspace extends Model catch error if error.message.endsWith('is a directory') atom.notifications.addWarning("Unable to save file: #{error.message}") - else if error.message.startsWith('EACCES,') - atom.notifications.addWarning("Unable to save file: #{error.message.replace('EACCES, ', '')}") + else if error.code is 'EACCES' and error.path? + atom.notifications.addWarning("Unable to save file: Permission denied '#{error.path}'") 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")