Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
start crash reporter as early as possible
Browse files Browse the repository at this point in the history
improved handling for exceptions inside promises
related #4477
auditors: @bbondy @bsclifton
  • Loading branch information
bridiver committed Oct 3, 2016
1 parent e1274a3 commit bc2680d
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,35 @@
'use strict'

let ready = false
// TODO(bridiver) - this should also send a notification to Brave
process.on('uncaughtException', function (error) {

// Setup the crash handling
const CrashHerald = require('./crash-herald')
CrashHerald.init()

const handleUncaughtError = (error) => {
var message, ref, stack
stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message
message = 'Uncaught Exception:\n' + stack
console.error('An uncaught exception occurred in the main process ' + message)
setTimeout(() => {
if (!ready) {
console.error('Process failed to load within 60 seconds')
process.exit(1)
}
}, 60 * 1000)

// TODO(bridiver) - this should also send a notification to Brave

if (!ready) {
console.error('Waiting 60 seconds for process to load')
setTimeout(() => {
if (!ready) {
console.error('Process failed to load within 60 seconds')
process.exit(1)
}
}, 60 * 1000)
}
}
process.on('uncaughtException', function (error) {
handleUncaughtError(error)
})

process.on('unhandledRejection', function (error, promise) {
handleUncaughtError(error)
})

if (process.platform === 'win32') {
Expand All @@ -41,7 +58,6 @@ const appActions = require('../js/actions/appActions')
const downloadActions = require('../js/actions/downloadActions')
const SessionStore = require('./sessionStore')
const AppStore = require('../js/stores/appStore')
const CrashHerald = require('./crash-herald')
const PackageLoader = require('./package-loader')
const Extensions = require('./extensions')
const Filtering = require('./filtering')
Expand Down Expand Up @@ -413,7 +429,6 @@ app.on('ready', () => {
})
}
process.emit(messages.APP_INITIALIZED)
ready = true

if (CmdLine.newWindowURL) {
appActions.newWindow(Immutable.fromJS({
Expand Down Expand Up @@ -700,9 +715,6 @@ app.on('ready', () => {
Importer.init()
})

// Setup the crash handling
CrashHerald.init()

// This loads package.json into an object
// TODO: Seems like this can be done with app.getVersion() insteand?
PackageLoader.load((err, pack) => {
Expand All @@ -729,5 +741,6 @@ app.on('ready', () => {
Importer.init()
})
})
ready = true
})
})

1 comment on commit bc2680d

@bbondy
Copy link
Member

@bbondy bbondy commented on bc2680d Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ but please check here because it'll have to move again:
#4479

You might want to give specific advise, but I think it needs to be handled similar to smooth scrolling which does a sync read of the state on startup.

Please sign in to comment.