mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-28 05:28:30 +00:00
Add settings for controlling the error reporting system.
Fix issues with destroying rooms and users. Fix the control center not being available on certain pages. Fix the host menu appearing when you aren't logged in. Clean up some old CSS.
This commit is contained in:
parent
e773600a3e
commit
92917453a7
12 changed files with 272 additions and 106 deletions
185
src/raven.js
185
src/raven.js
|
@ -25,6 +25,22 @@ const BAD_QUERIES = [
|
|||
];
|
||||
|
||||
|
||||
const ERROR_TYPES = [
|
||||
Error,
|
||||
TypeError,
|
||||
SyntaxError,
|
||||
ReferenceError
|
||||
];
|
||||
|
||||
const ERROR_STRINGS = [
|
||||
'the ducks are on fire',
|
||||
"it's raining in shanghai",
|
||||
'can we just not do this today?',
|
||||
'cbenni likes butts',
|
||||
'guys can you please not spam the errors my mom bought me this new error report server and it gets really hot when the errors are being spammed now my leg is starting to hurt because it is getting so hot'
|
||||
];
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// Raven Logger
|
||||
// ============================================================================
|
||||
|
@ -37,6 +53,68 @@ export default class RavenLogger extends Module {
|
|||
this.inject('site');
|
||||
this.inject('experiments');
|
||||
|
||||
// Do these in an event handler because we're initialized before
|
||||
// settings are even ready.
|
||||
this.once('settings:enabled', () => {
|
||||
this.settings.add('reports.error.enable', {
|
||||
default: true,
|
||||
ui: {
|
||||
path: 'Data Management > Reporting >> Error Reports',
|
||||
title: 'Automatically send reports when an error occurs.',
|
||||
component: 'setting-check-box'
|
||||
}
|
||||
});
|
||||
|
||||
this.settings.add('reports.error.include-user', {
|
||||
default: true,
|
||||
ui: {
|
||||
path: 'Data Management > Reporting >> Error Reports',
|
||||
title: 'Include user IDs in reports.',
|
||||
description: "Occasionally, it's useful to know which users are encountering issues so that we can check for specific badges, emote sets, or user flags that are causing issues.",
|
||||
component: 'setting-check-box'
|
||||
}
|
||||
});
|
||||
|
||||
this.settings.add('reports.error.include-settings', {
|
||||
default: true,
|
||||
ui: {
|
||||
path: 'Data Management > Reporting >> Error Reports',
|
||||
title: 'Include a settings snapshot in reports.',
|
||||
description: 'Knowing exactly what settings are in effect when an error happens can be incredibly useful for recreating the issue.',
|
||||
component: 'setting-check-box'
|
||||
}
|
||||
});
|
||||
|
||||
this.settings.addUI('reports.error.example', {
|
||||
path: 'Data Management > Reporting >> Error Reports',
|
||||
component: 'example-report',
|
||||
|
||||
watch: [
|
||||
'reports.error.enable',
|
||||
'reports.error.include-user',
|
||||
'reports.error.include-settings'
|
||||
],
|
||||
|
||||
data: () => new Promise(r => {
|
||||
// Why fake an error when we can *make* an error?
|
||||
this.__example_waiter = r;
|
||||
|
||||
// Generate the error in a timeout so that the end user
|
||||
// won't have a huge wall of a fake stack trace wasting
|
||||
// their time.
|
||||
|
||||
const type = ERROR_TYPES[Math.floor(Math.random() * ERROR_TYPES.length)],
|
||||
msg = ERROR_STRINGS[Math.floor(Math.random() * ERROR_STRINGS.length)];
|
||||
|
||||
setTimeout(() => this.log.capture(new type(msg), {
|
||||
tags: {
|
||||
example: true
|
||||
}
|
||||
}));
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
this.raven = Raven;
|
||||
|
||||
Raven.config(SENTRY_ID, {
|
||||
|
@ -72,59 +150,91 @@ export default class RavenLogger extends Module {
|
|||
|
||||
return true;
|
||||
},
|
||||
shouldSendCallback(data) {
|
||||
shouldSendCallback: data => {
|
||||
if ( this.settings && ! this.settings.get('reports.error.enable') ) {
|
||||
if ( data.tags.example && this.__example_waiter ) {
|
||||
this.__example_waiter(null);
|
||||
this.__example_waiter = null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// We don't want any of Sentry's junk.
|
||||
if ( data.message && data.messages.includes('raven-js/') )
|
||||
return false;
|
||||
|
||||
// We don't want any of Mozilla's junk either.
|
||||
const exc = data.exception && data.exception.values[0];
|
||||
if ( exc && exc.type.startsWith('NS_') )
|
||||
return false;
|
||||
|
||||
// Apparently, something is completely screwing up the DOM for
|
||||
// at least two users? Not our problem.
|
||||
if ( ! document.body || ! document.body.querySelector )
|
||||
return false;
|
||||
|
||||
if ( this.settings && this.settings.get('reports.error.include-user') ) {
|
||||
const user = this.site && this.site.getUser();
|
||||
if ( user )
|
||||
data.user = {id: user.id, username: user.login}
|
||||
}
|
||||
|
||||
data.extra = Object.assign(this.buildExtra(), data.extra);
|
||||
data.tags = Object.assign(this.buildTags(), data.tags);
|
||||
|
||||
if ( data.tags.example ) {
|
||||
if ( this.__example_waiter ) {
|
||||
this.__example_waiter(data);
|
||||
this.__example_waiter = null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}).install();
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
const user = this.site.getUser();
|
||||
if ( user )
|
||||
this.raven.setUserContext({
|
||||
id: user.id,
|
||||
username: user.login
|
||||
});
|
||||
this.log.info('Installed error tracking.');
|
||||
}
|
||||
|
||||
|
||||
buildExtra() {
|
||||
const context = this.settings.main_context,
|
||||
chat_context = this.resolve('chat').context;
|
||||
|
||||
|
||||
const settings = {},
|
||||
chat_settings = {},
|
||||
modules = {},
|
||||
const modules = {},
|
||||
experiments = {},
|
||||
twitch_experiments = {},
|
||||
out = {
|
||||
experiments,
|
||||
twitch_experiments,
|
||||
modules,
|
||||
settings,
|
||||
settings_context: context._context,
|
||||
chat_settings,
|
||||
chat_context: chat_context._context
|
||||
modules
|
||||
};
|
||||
|
||||
for(const key in this.__modules)
|
||||
if ( has(this.__modules, key) ) {
|
||||
const mod = this.__modules[key];
|
||||
modules[key] = [
|
||||
mod.loaded ? 'loaded' : mod.loading ? 'loading' : 'unloaded',
|
||||
mod.enabled ? 'enabled' : mod.enabling ? 'enabling' : 'disabled'
|
||||
]
|
||||
modules[key] = `${
|
||||
mod.loaded ? 'loaded' : mod.loading ? 'loading' : 'unloaded'} ${
|
||||
mod.enabled ? 'enabled' : mod.enabling ? 'enabling' : 'disabled'}`;
|
||||
}
|
||||
|
||||
for(const [key, value] of context.__cache.entries())
|
||||
settings[key] = value;
|
||||
if ( this.settings && this.settings.get('reports.error.include-settings') ) {
|
||||
const context = this.settings.main_context,
|
||||
chat = this.resolve('chat'),
|
||||
chat_context = chat && chat.context,
|
||||
|
||||
for(const [key, value] of chat_context.__cache.entries())
|
||||
chat_settings[key] = value;
|
||||
settings = out.settings = {},
|
||||
chat_settings = out.chat_setting = chat_context ? {} : undefined;
|
||||
|
||||
for(const [key, value] of context.__cache.entries())
|
||||
settings[key] = value;
|
||||
|
||||
if ( chat_context )
|
||||
for(const [key, value] of chat_context.__cache.entries())
|
||||
chat_settings[key] = value;
|
||||
}
|
||||
|
||||
for(const [key, value] of Object.entries(this.experiments.getTwitchExperiments()))
|
||||
if ( this.experiments.usingTwitchExperiment(key) )
|
||||
|
@ -150,25 +260,8 @@ export default class RavenLogger extends Module {
|
|||
}
|
||||
|
||||
|
||||
|
||||
addPlugin(...args) { return this.raven.addPlugin(...args) }
|
||||
setUserContext(...args) { return this.raven.setUserContext(...args) }
|
||||
|
||||
captureException(exc, opts) {
|
||||
opts = opts || {};
|
||||
opts.extra = Object.assign(this.buildExtra(), opts.extra);
|
||||
opts.tags = Object.assign(this.buildTags(), opts.tags);
|
||||
|
||||
return this.raven.captureException(exc, opts);
|
||||
}
|
||||
|
||||
captureMessage(msg, opts) {
|
||||
opts = opts || {};
|
||||
opts.extra = Object.assign(this.buildExtra(), opts.extra);
|
||||
opts.tags = Object.assign(this.buildTags(), opts.tags);
|
||||
|
||||
return this.raven.captureMessage(msg, opts);
|
||||
}
|
||||
|
||||
captureException(exc, opts) { return this.raven.captureException(exc, opts) }
|
||||
captureMessage(msg, opts) { return this.raven.captureMessage(msg, opts) }
|
||||
captureBreadcrumb(...args) { return this.raven.captureBreadcrumb(...args) }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue