Telemetry: report uncaught errors
This commit is contained in:
@@ -68,6 +68,13 @@ function init () {
|
|||||||
|
|
||||||
// To keep app startup fast, some code is delayed.
|
// To keep app startup fast, some code is delayed.
|
||||||
setTimeout(delayedInit, config.DELAYED_INIT)
|
setTimeout(delayedInit, config.DELAYED_INIT)
|
||||||
|
|
||||||
|
// Report uncaught exceptions
|
||||||
|
process.on('uncaughtException', (err) => {
|
||||||
|
console.error(err)
|
||||||
|
var errJSON = {message: err.message, stack: err.stack}
|
||||||
|
windows.main.dispatch('uncaughtError', 'main', errJSON)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
app.once('ipcReady', function () {
|
app.once('ipcReady', function () {
|
||||||
|
|||||||
@@ -95,9 +95,11 @@ function onState (err, _state) {
|
|||||||
// ...window visibility state.
|
// ...window visibility state.
|
||||||
document.addEventListener('webkitvisibilitychange', onVisibilityChange)
|
document.addEventListener('webkitvisibilitychange', onVisibilityChange)
|
||||||
|
|
||||||
sound.play('STARTUP')
|
// Log uncaught JS errors
|
||||||
|
window.addEventListener('error', (err) => telemetry.logUncaughtError('window', err.error), true)
|
||||||
|
|
||||||
// Done! Ideally we want to get here < 500ms after the user clicks the app
|
// Done! Ideally we want to get here < 500ms after the user clicks the app
|
||||||
|
sound.play('STARTUP')
|
||||||
console.timeEnd('init')
|
console.timeEnd('init')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,6 +329,9 @@ function dispatch (action, ...args) {
|
|||||||
if (action === 'setTitle') {
|
if (action === 'setTitle') {
|
||||||
state.window.title = args[0] /* title */
|
state.window.title = args[0] /* title */
|
||||||
}
|
}
|
||||||
|
if (action === 'uncaughtError') {
|
||||||
|
telemetry.logUncaughtError(args[0] /* process */, args[1] /* error */)
|
||||||
|
}
|
||||||
|
|
||||||
// Update the virtual-dom, unless it's just a mouse move event
|
// Update the virtual-dom, unless it's just a mouse move event
|
||||||
if (action !== 'mediaMouseMoved' || showOrHidePlayerControls()) {
|
if (action !== 'mediaMouseMoved' || showOrHidePlayerControls()) {
|
||||||
@@ -481,6 +486,8 @@ function setupIpc () {
|
|||||||
ipcRenderer.on('wt-audio-metadata', (e, ...args) => torrentAudioMetadata(...args))
|
ipcRenderer.on('wt-audio-metadata', (e, ...args) => torrentAudioMetadata(...args))
|
||||||
ipcRenderer.on('wt-server-running', (e, ...args) => torrentServerRunning(...args))
|
ipcRenderer.on('wt-server-running', (e, ...args) => torrentServerRunning(...args))
|
||||||
|
|
||||||
|
ipcRenderer.on('wt-uncaught-error', (e, err) => telemetry.logUncaughtError('webtorrent', err))
|
||||||
|
|
||||||
ipcRenderer.send('ipcReady')
|
ipcRenderer.send('ipcReady')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ function init () {
|
|||||||
|
|
||||||
ipc.send('ipcReadyWebTorrent')
|
ipc.send('ipcReadyWebTorrent')
|
||||||
|
|
||||||
|
window.addEventListener('error', (err) =>
|
||||||
|
ipc.send('wt-uncaught-error', {message: err.error.message, stack: err.error.stack}))
|
||||||
|
|
||||||
setInterval(updateTorrentProgress, 1000)
|
setInterval(updateTorrentProgress, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
telemetry.js
13
telemetry.js
@@ -47,7 +47,6 @@ function reset () {
|
|||||||
|
|
||||||
function postToServer () {
|
function postToServer () {
|
||||||
// Serialize the telemetry summary
|
// Serialize the telemetry summary
|
||||||
return console.log(JSON.stringify(telemetry, null, 2))
|
|
||||||
var payload = new Buffer(JSON.stringify(telemetry), 'utf8')
|
var payload = new Buffer(JSON.stringify(telemetry), 'utf8')
|
||||||
|
|
||||||
// POST to our server
|
// POST to our server
|
||||||
@@ -111,14 +110,16 @@ function getApproxNumTorrents (state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// An uncaught error happened in the main process or one in one of the windows
|
// An uncaught error happened in the main process or one in one of the windows
|
||||||
function logUncaughtError (err) {
|
function logUncaughtError (process, err) {
|
||||||
var errString
|
var message, stack
|
||||||
if (typeof err === 'string') {
|
if (typeof err === 'string') {
|
||||||
errString = err
|
message = err
|
||||||
|
stack = ''
|
||||||
} else {
|
} else {
|
||||||
errString = err.message + '\n' + err.stack
|
message = err.message
|
||||||
|
stack = err.stack
|
||||||
}
|
}
|
||||||
telemetry.uncaughtErrors.push(errString)
|
telemetry.uncaughtErrors.push({process, message, stack})
|
||||||
}
|
}
|
||||||
|
|
||||||
// The user pressed play. It either worked, timed out, or showed the
|
// The user pressed play. It either worked, timed out, or showed the
|
||||||
|
|||||||
Reference in New Issue
Block a user