-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error reporting, reduce data that being sent
- Loading branch information
Showing
7 changed files
with
218 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
var child_process = require('child_process'); | ||
var colors = require('colors/safe'); | ||
|
||
var initSentry = function initSentry() { | ||
if (process.env.POSTBIRD_DEV != "true") { | ||
var Sentry = require('@sentry/electron'); | ||
var integrationsPkg = require("@sentry/integrations"); | ||
Sentry.init({ | ||
dsn: 'https://07fa68e1ac02484e9370fc9f0b77631f:[email protected]/143647', | ||
debug: false, | ||
appName: 'Postbird', | ||
integrations: function(integrations) { | ||
integrations.push(new integrationsPkg.Dedupe()); | ||
return integrations; | ||
}, | ||
beforeBreadcrumb(breadcrumb, hint) { | ||
return null; | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
var errorReporter = function errorReporter(exception /*: PgError */, showError = true) { | ||
setTimeout(function () { | ||
// skip errors while developing | ||
if (process.env.NW_DEV == "true") { | ||
if (process.env.POSTBIRD_DEV == "true") { | ||
logger.info("Skip error reporting"); | ||
logger.info(exception.stack); | ||
try { | ||
|
@@ -20,7 +38,8 @@ var errorReporter = function errorReporter(exception /*: PgError */, showError = | |
exception.message.includes("server closed the connection unexpectedly") || | ||
exception.message.includes("Unable to set non-blocking to true") || | ||
exception.message.includes("Client has encountered a connection error and is not queryable") || | ||
exception.message.includes("Connection terminated") | ||
exception.message.includes("Connection terminated") || | ||
exception.message.includes("current transaction is aborted,") | ||
) { | ||
console.log("Skip error reporting"); | ||
console.error(exception.stack); | ||
|
@@ -35,58 +54,12 @@ var errorReporter = function errorReporter(exception /*: PgError */, showError = | |
exception.client = "CUT!"; | ||
} | ||
|
||
var Raven = require('raven'); | ||
Raven.config('https://07fa68e1ac02484e9370fc9f0b77631f:[email protected]/143647', { | ||
logger: 'default', | ||
allowSecretKey: true, | ||
transport: { | ||
send(client, message, headers, eventId, cb) { | ||
setTimeout(() => { | ||
try { | ||
var net = require('electron').remote.net; | ||
var request = net.request({ | ||
method: 'POST', | ||
protocol: 'https:', | ||
hostname: client.dsn.host, | ||
path: client.dsn.path + 'api/' + client.dsn.project_id + '/store/', | ||
headers: headers, | ||
port: 443 | ||
}); | ||
|
||
request.on('error', error => { | ||
console.error(error); | ||
}); | ||
|
||
request.on('abort', error => { | ||
console.error('abort', error); | ||
}); | ||
|
||
request.on('response', res => { | ||
console.log('Error reported'); | ||
}); | ||
|
||
request.end(message); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}, 100); | ||
} | ||
} | ||
}).install(); | ||
|
||
// initSentry(); | ||
var Sentry = require('@sentry/electron'); | ||
var electron = require('electron'); | ||
var electronVersion; | ||
try { | ||
electronVersion = electron.remote.process.versions.electron; | ||
} catch (e) { | ||
console.error(e.stack); | ||
} | ||
|
||
var extra /*: any */ = { | ||
user: global.process.env.USER, | ||
pwd: global.process.env.PWD, | ||
arch: global.process.arch, | ||
version_el: electronVersion | ||
}; | ||
|
||
try { | ||
|
@@ -104,20 +77,15 @@ var errorReporter = function errorReporter(exception /*: PgError */, showError = | |
console.error(error); | ||
} | ||
|
||
var sender = function () { | ||
Raven.setContext({user: extra}); | ||
Raven.captureException(exception); | ||
}; | ||
|
||
if (process.platform == "darwin") { | ||
var exec = child_process.exec; | ||
exec('sw_vers -productVersion', function (err, stdout) { | ||
extra.system = stdout; | ||
sender(); | ||
}); | ||
} else { | ||
sender(); | ||
if (global.App.currentTab) { | ||
extra.appTab = global.App.currentTab.name; | ||
extra.appPane = global.App.currentTab.instance.currentTab; | ||
} | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setExtra('user', extra); | ||
}); | ||
Sentry.captureException(exception); | ||
}); | ||
|
||
if (global.logger) { | ||
|
@@ -129,14 +97,20 @@ var errorReporter = function errorReporter(exception /*: PgError */, showError = | |
} | ||
|
||
if (showError) { | ||
if (exception instanceof Error) { | ||
window.alert(exception.message + "\n" + exception.stack); | ||
} else { | ||
window.alert(exception); | ||
try { | ||
if (exception instanceof Error) { | ||
window.alert(exception.message + "\n" + exception.stack); | ||
} else { | ||
window.alert(exception); | ||
} | ||
} catch (e) { | ||
console.log("can not show error", e); | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
errorReporter.init = initSentry; | ||
|
||
process.on("uncaughtException", errorReporter); | ||
module.exports = errorReporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/bash | ||
|
||
export NW_DEV=true | ||
export NW_DEBUG=true | ||
export POSTBIRD_DEV=true | ||
export POSTBIRD_DEBUG=true | ||
|
||
node_modules/.bin/electron . $@ |
Oops, something went wrong.