mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Catch read errors during deserialization
Prevents Atom from failing to open because of a read error with a serialized editor.
This commit is contained in:
@@ -16,6 +16,19 @@ describe "Workspace", ->
|
||||
atom.project.setPaths([atom.project.getDirectories()[0]?.resolve('dir')])
|
||||
atom.workspace = workspace = new Workspace
|
||||
|
||||
describe "serialization", ->
|
||||
it "does not deserialize text editors for files that can't be read", ->
|
||||
pathToOpen = path.join(temp.mkdirSync(), 'file.txt')
|
||||
|
||||
waitsForPromise ->
|
||||
workspace.open(pathToOpen)
|
||||
|
||||
runs ->
|
||||
expect(workspace.getPaneItems().length).toBe 1
|
||||
fs.mkdirSync(pathToOpen)
|
||||
deserializedWorkspace = atom.workspace.testSerialization()
|
||||
expect(deserializedWorkspace.getPaneItems().length).toBe 0
|
||||
|
||||
describe "::open(uri, options)", ->
|
||||
openEvents = null
|
||||
|
||||
|
||||
@@ -128,7 +128,15 @@ class TextEditor extends Model
|
||||
displayBuffer: @displayBuffer.serialize()
|
||||
|
||||
deserializeParams: (params) ->
|
||||
params.displayBuffer = DisplayBuffer.deserialize(params.displayBuffer)
|
||||
try
|
||||
displayBuffer = DisplayBuffer.deserialize(params.displayBuffer)
|
||||
catch error
|
||||
if error.syscall is 'read'
|
||||
return # Error reading the file, don't deserialize an editor for it
|
||||
else
|
||||
throw error
|
||||
|
||||
params.displayBuffer = displayBuffer
|
||||
params.registerEditor = true
|
||||
params
|
||||
|
||||
|
||||
Reference in New Issue
Block a user