mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Merge pull request #7802 from atom/ks-handle-more-save-errors
Handle more open/save error codes with custom notifications
This commit is contained in:
@@ -491,7 +491,7 @@ class Pane extends Model
|
||||
try
|
||||
item.save?()
|
||||
catch error
|
||||
@handleSaveError(error)
|
||||
@handleSaveError(error, item)
|
||||
nextAction?()
|
||||
else
|
||||
@saveItemAs(item, nextAction)
|
||||
@@ -512,7 +512,7 @@ class Pane extends Model
|
||||
try
|
||||
item.saveAs(newItemPath)
|
||||
catch error
|
||||
@handleSaveError(error)
|
||||
@handleSaveError(error, item)
|
||||
nextAction?()
|
||||
|
||||
# Public: Save all items.
|
||||
@@ -676,19 +676,32 @@ class Pane extends Model
|
||||
return false unless @promptToSaveItem(item)
|
||||
true
|
||||
|
||||
handleSaveError: (error) ->
|
||||
handleSaveError: (error, item) ->
|
||||
itemPath = error.path ? item.getPath?()
|
||||
addWarningWithPath = (message, options) ->
|
||||
message = "#{message} '#{itemPath}'" if itemPath
|
||||
atom.notifications.addWarning(message, options)
|
||||
|
||||
if error.code is 'EISDIR' or 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 in ['EPERM', 'EBUSY', 'UNKNOWN', 'EEXIST'] 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 error.code is 'ENOSPC' and error.path?
|
||||
atom.notifications.addWarning("Unable to save file: No space left on device '#{error.path}'")
|
||||
else if error.code is 'ENXIO' and error.path?
|
||||
atom.notifications.addWarning("Unable to save file: No such device or address '#{error.path}'")
|
||||
else if error.code is 'EACCES'
|
||||
addWarningWithPath('Unable to save file: Permission denied')
|
||||
else if error.code in ['EPERM', 'EBUSY', 'UNKNOWN', 'EEXIST']
|
||||
addWarningWithPath('Unable to save file', detail: error.message)
|
||||
else if error.code is 'EROFS'
|
||||
addWarningWithPath('Unable to save file: Read-only file system')
|
||||
else if error.code is 'ENOSPC'
|
||||
addWarningWithPath('Unable to save file: No space left on device')
|
||||
else if error.code is 'ENXIO'
|
||||
addWarningWithPath('Unable to save file: No such device or address')
|
||||
else if error.code is 'ENOTSUP'
|
||||
addWarningWithPath('Unable to save file: Operation not supported on socket')
|
||||
else if error.code is 'EIO'
|
||||
addWarningWithPath('Unable to save file: I/O error writing file')
|
||||
else if error.code is 'EINTR'
|
||||
addWarningWithPath('Unable to save file: Interrupted system call')
|
||||
else if error.code is 'ESPIPE'
|
||||
addWarningWithPath('Unable to save file: Invalid seek')
|
||||
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")
|
||||
|
||||
@@ -442,7 +442,7 @@ class Workspace extends Model
|
||||
when 'EACCES'
|
||||
atom.notifications.addWarning("Permission denied '#{error.path}'")
|
||||
return Q()
|
||||
when 'EPERM', 'EBUSY'
|
||||
when 'EPERM', 'EBUSY', 'ENXIO', 'EIO', 'ENOTCONN', 'UNKNOWN'
|
||||
atom.notifications.addWarning("Unable to open '#{error.path}'", detail: error.message)
|
||||
return Q()
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user