Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/main.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{Notification, CompositeDisposable} = require 'atom'
fs = require 'fs-plus'
StackTraceParser = null

Notifications =
isInitialized: false
Expand Down Expand Up @@ -34,6 +36,11 @@ Notifications =

else if !atom.inDevMode() or atom.config.get('notifications.showErrorsInDevMode')
preventDefault()

# Ignore errors with no paths in them since they are impossible to trace
if originalError.stack and not isCoreOrPackageStackTrace(originalError.stack)
return

options =
detail: "#{url}:#{line}"
stack: originalError.stack
Expand Down Expand Up @@ -94,6 +101,12 @@ Notifications =
notification.setDisplayed(true)
@lastNotification = notification

isCoreOrPackageStackTrace = (stack) ->
StackTraceParser ?= require 'stacktrace-parser'
for {file} in StackTraceParser.parse(stack)
return true if fs.isAbsolute(file)
false

if atom.inDevMode()
atom.commands.add 'atom-workspace', 'notifications:toggle-dev-panel', -> Notifications.togglePanel()
atom.commands.add 'atom-workspace', 'notifications:trigger-error', ->
Expand Down
14 changes: 14 additions & 0 deletions spec/notifications-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ describe "Notifications", ->
expect(notificationContainer.childNodes.length).toBe 0
expect(fatalError).toBe null

describe "when the exception has no core or package paths in the stack trace", ->
it "does not display a notification", ->
atom.notifications.clear()
spyOn(atom, 'inDevMode').andReturn false
handler = jasmine.createSpy('onWillThrowErrorHandler')
atom.onWillThrowError(handler)
fs.readFile(__dirname)

waitsFor ->
handler.callCount is 1

runs ->
expect(atom.notifications.getNotifications().length).toBe 0

describe "when there are multiple packages in the stack trace", ->
beforeEach ->
stack = """
Expand Down