From 3850550345c16ac646ab70fd8247ed086442deaf Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 5 Feb 2015 14:42:21 -0800 Subject: [PATCH] Handle save errors in Pane --- src/pane.coffee | 27 +++++++++++++++++++++++++-- src/window-bootstrap.coffee | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/pane.coffee b/src/pane.coffee index 8524e3fae..8ba70fc76 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -481,7 +481,10 @@ class Pane extends Model itemURI = item.getUri() if itemURI? - item.save?() + try + item.save?() + catch + @handleSaveError(error) nextAction?() else @saveItemAs(item, nextAction) @@ -498,7 +501,10 @@ class Pane extends Model itemPath = item.getPath?() newItemPath = atom.showSaveDialogSync(itemPath) if newItemPath - item.saveAs(newItemPath) + try + item.saveAs(newItemPath) + catch error + @handleSaveError(error) nextAction?() # Public: Save all items. @@ -667,3 +673,20 @@ class Pane extends Model for item in @getItems() return false unless @promptToSaveItem(item) true + + handleSaveError: (error) -> + if error.message.endsWith('is a directory') + 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 error.code is 'EBUSY' and error.path? + atom.notifications.addWarning("Unable to save file '#{error.path}'", detail: error.message) + else if error.code is 'EROFS' and error.path? + atom.notifications.addWarning("Unable to save file: Read-only file system '#{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") + else + throw error diff --git a/src/window-bootstrap.coffee b/src/window-bootstrap.coffee index 886ba26dc..6b3f1a846 100644 --- a/src/window-bootstrap.coffee +++ b/src/window-bootstrap.coffee @@ -1,10 +1,12 @@ # Like sands through the hourglass, so are the days of our lives. +console.profile('loading') require './window' Atom = require './atom' window.atom = Atom.loadOrCreate('editor') atom.initialize() atom.startEditorWindow() +console.profileEnd('loading') # Workaround for focus getting cleared upon window creation windowFocused = ->