Catch and log deactivate errors

Closes #3538
This commit is contained in:
Kevin Sawicki
2014-09-15 08:34:21 -07:00
parent 10762d6440
commit 8c2bcf3943
3 changed files with 20 additions and 2 deletions

View File

@@ -350,7 +350,7 @@ describe "the `atom` global", ->
atom.packages.deactivatePackage("package-that-throws-on-activate")
expect(badPack.mainModule.serialize).not.toHaveBeenCalled()
it "absorbs exceptions that are thrown by the package module's serialize methods", ->
it "absorbs exceptions that are thrown by the package module's serialize method", ->
spyOn(console, 'error')
waitsForPromise ->
@@ -365,6 +365,16 @@ describe "the `atom` global", ->
expect(atom.packages.packageStates['package-with-serialization']).toEqual someNumber: 1
expect(console.error).toHaveBeenCalled()
it "absorbs exceptions that are thrown by the package module's deactivate method", ->
spyOn(console, 'error')
waitsForPromise ->
atom.packages.activatePackage("package-that-throws-on-deactivate")
runs ->
expect(-> atom.packages.deactivatePackage("package-that-throws-on-deactivate")).not.toThrow()
expect(console.error).toHaveBeenCalled()
it "removes the package's grammars", ->
waitsForPromise ->
atom.packages.activatePackage('package-with-grammars')

View File

@@ -0,0 +1,4 @@
module.exports =
activate: ->
deactivate: -> throw new Error('Top that')
serialize: ->

View File

@@ -273,7 +273,11 @@ class Package
@unsubscribeFromActivationEvents()
@deactivateResources()
@deactivateConfig()
@mainModule?.deactivate?() if @mainActivated
if @mainActivated
try
@mainModule?.deactivate?()
catch e
console.error "Error deactivating package '#{@name}'", e.stack
@emit 'deactivated'
@emitter.emit 'did-deactivate'