jsformat-atom
jsformat-atom copied to clipboard
Uncaught TypeError: Cannot read property 'dispose' of undefined
From @MichaelReeder on December 10, 2014 14:43
Uncaught TypeError: Cannot read property 'dispose' of undefined
Atom Version: 0.154.0 System: Mac OS X 10.9.3 Thrown From: jsformat package
Steps To Reproduce
- ...
- ...
Stack Trace
At /Users/michaelreeder/.atom/packages/jsformat/lib/format.coffee:111
TypeError: Cannot read property 'dispose' of undefined
at /Users/michaelreeder/.atom/packages/jsformat/lib/format.coffee:111:48
at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:82:11)
at TextBuffer.module.exports.TextBuffer.destroy (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:1049:22)
at TextBuffer.module.exports.TextBuffer.release (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:1074:14)
at TextEditor.module.exports.TextEditor.destroyed (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:260:19)
at TextEditor.module.exports.Model.destroy (/Applications/Atom.app/Contents/Resources/app/node_modules/theorist/lib/model.js:218:14)
at Pane.module.exports.Pane.destroyItem (/Applications/Atom.app/Contents/Resources/app/src/pane.js:445:18)
at TabBarView.module.exports.TabBarView.closeTab (/Applications/Atom.app/Contents/Resources/app/node_modules/tabs/lib/tab-bar-view.js:267:24)
at TabBarView.module.exports.TabBarView.closeAllTabs (/Applications/Atom.app/Contents/Resources/app/node_modules/tabs/lib/tab-bar-view.js:342:28)
at space-pen-ul.subscriptions.add.atom.commands.add.tabs:close-all-tabs (/Applications/Atom.app/Contents/Resources/app/node_modules/tabs/lib/tab-bar-view.js:67:26)
at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app/src/command-registry.js:243:29)
at CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app/src/command-registry.js:3:61)
at CommandRegistry.module.exports.CommandRegistry.dispatch (/Applications/Atom.app/Contents/Resources/app/src/command-registry.js:156:19)
at [object Object].jQuery.fn.trigger (/Applications/Atom.app/Contents/Resources/app/src/space-pen-extensions.js:64:23)
at Ipc.<anonymous> (/Applications/Atom.app/Contents/Resources/app/src/window-event-handler.js:70:67)
at Ipc.emit (events.js:110:17)
at process.<anonymous> (/Applications/Atom.app/Contents/Resources/atom/renderer/api/lib/ipc.js:22:29)
at process.emit (events.js:118:17)
at Ipc.sendSync (/Applications/Atom.app/Contents/Resources/atom/renderer/api/lib/ipc.js:39:29)
at Ipc.sendChannelSync (/Applications/Atom.app/Contents/Resources/atom/renderer/api/lib/ipc.js:47:28)
at BrowserWindow.RemoteMemberFunction [as emit] (/Applications/Atom.app/Contents/Resources/atom/renderer/api/lib/remote.js:110:29)
at ContextMenuManager.module.exports.ContextMenuManager.showForEvent (/Applications/Atom.app/Contents/Resources/app/src/context-menu-manager.js:169:33)
at HTMLDocument.<anonymous> (/Applications/Atom.app/Contents/Resources/app/src/window-event-handler.js:138:33)
at HTMLDocument.handler (/Applications/Atom.app/Contents/Resources/app/src/space-pen-extensions.js:112:34)
at HTMLDocument.jQuery.event.dispatch (/Applications/Atom.app/Contents/Resources/app/node_modules/space-pen/vendor/jquery.js:4681:9)
at HTMLDocument.elemData.handle (/Applications/Atom.app/Contents/Resources/app/node_modules/space-pen/vendor/jquery.js:4359:46)
Copied from original issue: atom/atom#4504
@benogle I've run into this error before, but I can't reproduce it. Debugging also shows that the particular line is almost never even called...I've found a lot of API inconsistencies and changes, is it possible that this snippet doesn't work anymore:
@editorCloseSubscriptions[editor.id] = buffer.onDidDestroy =>
@editorSaveSubscriptions[editor.id].dispose()
@editorCloseSubscriptions[editor.id].dispose()
delete @editorSaveSubscriptions[editor.id]
delete @editorCloseSubscriptions[editor.id]
A symptom fix could be to add ?
before the dispose calls: @editorSaveSubscriptions[editor.id]?.dispose()
But shouldn't it be set here. I'm not really sure it's set all the time, but that means the event callback isn't run if the code is correct.
@editorSaveSubscriptions[editor.id] = buffer.onWillSave =>
if buffer.isModified()
buffer.transact =>
@format(state)
Suggestions?
I'm not totally following. You can use CompositeDisposable
s in that code though, rather than a save and a close hash, just one editorSubscriptions
hash.
I think I see the problem. It's cause there can be multiple editors for each buffer. Is there a reason you're using buffers in that code rather than editors? Can you subscribe to the editors instead?
Right, but if I need to dispose of one subscription, the composite won't do it. I was going to write a wrapper, but that just hides the hash in a class along with a composite..so I didn't think it would be very useful.
The textEditor API doesn't seem to provide an onWillSave
event, unlike Buffer which does. It does have onDidDestroy
though.
Is there a way to subscribe to the onWillSave
event for text editors? If so, then you can just point me to some docs and I think I'll be able to implement it pretty easily assuming it's the same API style.
@benogle any answer to my previous comment?