Show notifications on load/activate errors

This commit is contained in:
Kevin Sawicki
2015-03-03 16:08:10 -08:00
parent c172f78ab5
commit 8ba434f4c4

View File

@@ -126,9 +126,8 @@ class Package
@loadStylesheets()
@settingsPromise = @loadSettings()
@requireMainModule() unless @hasActivationCommands()
catch error
console.warn "Failed to load package named '#{@name}'", error.stack ? error
@handleError("Failed to load the #{@name} package", error)
this
reset: ->
@@ -148,8 +147,12 @@ class Package
if @hasActivationCommands()
try
@subscribeToActivationCommands()
catch e
console.warn "Failed to subscribe to activation commands for package '#{@name}'", e.stack
catch error
if error.code is 'EBADSELECTOR'
metadataPath = path.join(@path, 'package.json')
error.message += " in #{metadataPath}"
error.stack += "\n at #{metadataPath}:1:1"
@handleError("Failed to activate the #{@name} package", error)
else
@activateNow()
@@ -163,8 +166,8 @@ class Package
@mainModule.activate?(atom.packages.getPackageState(@name) ? {})
@mainActivated = true
@activateServices()
catch e
console.warn "Failed to activate package named '#{@name}'", e.stack
catch error
@handleError("Failed to activate the #{@name} package", error)
@activationDeferred?.resolve()
@@ -531,3 +534,18 @@ class Package
@compatible = @incompatibleModules.length is 0
else
@compatible = true
handleError: (message, error) ->
if error.filename and error.location and (error instanceof SyntaxError)
location = "#{error.filename}:#{error.location.first_line + 1}:#{error.location.first_column + 1}"
detail = "#{error.message} in #{location}"
stack = """
SyntaxError: #{error.message}
at #{location}
"""
else
detail = error.message
stack = error.stack ? error
console.trace()
atom.notifications.addFatalError(message, {stack, detail, dismissable: true})