Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Save the error for later so error handling doesn't count to command process time
error = e;
}
const execTime = Date.now() - start;
if (error) {
this.client.stats.cmdErrors++;
if (error.code) {
const num = this.client.stats.cmdHttpErrors.get(error.code) || 0;
this.client.stats.cmdHttpErrors.set(error.code, num + 1);
}
console.error(error);
withScope(scope => {
if (guild) {
scope.setUser({ id: guild.id });
}
scope.setTag('command', cmd.name);
scope.setExtra('channel', channel.id);
scope.setExtra('message', message.content);
captureException(error);
});
if (guild) {
this.client.db.saveIncident(guild, {
id: null,
guildId: guild.id,
error: error.message,
details: {
command: cmd.name,
function reportToSentry(error: GraphQLError): void {
const errorCodesToIgnore = ["BAD_USER_INPUT", "GRAPHQL_VALIDATION_FAILED"];
const errorCode = error.extensions ? error.extensions.code : null;
if (errorCode && errorCodesToIgnore.includes(errorCode)) {
return;
}
Sentry.withScope((scope) => {
scope.setExtra("query", error.source);
Sentry.captureException(error.originalError || error);
});
}
sendException( error ) {
Sentry.withScope( scope => {
scope.setExtra( 'settings', settings.get() )
scope.setExtra( 'system', {
cpus: cpus(),
freeMemory: freemem(),
totalMemory: totalmem(),
platform: platform(),
networkInterfaces: networkInterfaces(),
} )
Sentry.captureException( error )
} )
}
export function message(message: string, extra: object) {
Sentry.withScope(scope => {
for (const key in extra) {
scope.setExtra(key, extra[key])
}
scope.setLevel(Sentry.Severity.Info)
Sentry.captureMessage(message)
})
}
captureException (error, meta = {}) {
Sentry.withScope(scope => {
scope.setUser({ ...meta })
Sentry.captureException(error)
})
}
function logToSentry({ error, details, currentUser }) {
Sentry.withScope(scope => {
if (currentUser) {
scope.setUser(getUserObject(currentUser));
}
Object.keys(details).forEach(key => {
scope.setExtra(key, details[key]);
});
Sentry.captureException(error);
});
}
addLogFunction(logToSentry);
export function exception(err: Error, extra: object) {
Sentry.withScope(scope => {
for (const key in extra) {
scope.setExtra(key, extra[key])
}
scope.setLevel(Sentry.Severity.Error)
Sentry.captureException(err)
})
}
captureMessage (message, meta = {}) {
Sentry.withScope(scope => {
scope.setUser({ ...meta })
Sentry.captureMessage(message, 'debug')
})
}
}
export function report(err, extra = {}) {
log.error(err.message);
if (!process.env.SENTRY_DSN) {
log.error(err);
return;
}
Sentry.withScope(scope => {
scope.setExtras(extra);
Sentry.captureException(err);
});
}