Adjusting how errors are logged

This should allow for working out any JS failures that may occur
This commit is contained in:
Jeff Avallone 2014-12-28 17:37:11 -05:00
parent cfaa3afa78
commit 5406487ae0
3 changed files with 27 additions and 20 deletions

View File

@ -262,9 +262,13 @@ describe('regexper.js', function() {
describe('#_trackEvent', function() { describe('#_trackEvent', function() {
beforeEach(function() {
spyOn(window._gaq, 'push');
});
it('adds a _trackEvent call to gaq', function() { it('adds a _trackEvent call to gaq', function() {
this.regexper._trackEvent('category', 'action'); this.regexper._trackEvent('category', 'action');
expect(this.regexper.gaq).toContain(['_trackEvent', 'category', 'action']); expect(window._gaq.push).toHaveBeenCalledWith(['_trackEvent', 'category', 'action']);
}); });
}); });
@ -407,27 +411,27 @@ describe('regexper.js', function() {
it('sets the state to be "has-error"', function(done) { it('sets the state to be "has-error"', function(done) {
this.regexper.renderRegexp('example expression') this.regexper.renderRegexp('example expression')
.then(fail, () => { .then(() => {
expect(this.regexper.state).toEqual('has-error'); expect(this.regexper.state).toEqual('has-error');
}) }, fail)
.finally(done) .finally(done)
.done(); .done();
}); });
it('displays the error message', function(done) { it('displays the error message', function(done) {
this.regexper.renderRegexp('example expression') this.regexper.renderRegexp('example expression')
.then(fail, () => { .then(() => {
expect(this.regexper.error.innerHTML).toEqual('Error: example parse error'); expect(this.regexper.error.innerHTML).toEqual('Error: example parse error');
}) }, fail)
.finally(done) .finally(done)
.done(); .done();
}); });
it('tracks the parse error', function(done) { it('tracks the parse error', function(done) {
this.regexper.renderRegexp('example expression') this.regexper.renderRegexp('example expression')
.then(fail, () => { .then(() => {
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'parse error'); expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'parse error');
}) }, fail)
.finally(done) .finally(done)
.done(); .done();
}); });
@ -553,15 +557,6 @@ describe('regexper.js', function() {
this.renderPromise.reject('example render failure'); this.renderPromise.reject('example render failure');
}); });
it('tracks the failed render', function(done) {
this.regexper.renderRegexp('example expression')
.then(fail, () => {
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'exception');
})
.finally(done)
.done();
});
it('sets the runningParser to false', function(done) { it('sets the runningParser to false', function(done) {
this.regexper.renderRegexp('example expression') this.regexper.renderRegexp('example expression')
.then(fail, () => { .then(fail, () => {

View File

@ -3,7 +3,20 @@ import Regexper from './regexper.js';
import Parser from './parser/javascript.js'; import Parser from './parser/javascript.js';
import _ from 'lodash'; import _ from 'lodash';
window._gaq = (typeof _gaq !== 'undefined') ? _gaq : {
push: console.debug.bind(console)
};
(function() { (function() {
window.addEventListener('error', function(error) {
_gaq.push([
'_trackEvent',
'global',
'exception',
`${error.filename}(${error.lineno}): ${error.message}`
]);
});
if (document.body.querySelector('#content .application')) { if (document.body.querySelector('#content .application')) {
var regexper = new Regexper(document.body); var regexper = new Regexper(document.body);

View File

@ -15,8 +15,6 @@ export default class Regexper {
this.percentage = root.querySelector('#progress div'); this.percentage = root.querySelector('#progress div');
this.svgContainer = root.querySelector('#regexp-render'); this.svgContainer = root.querySelector('#regexp-render');
this.svgBase = this.root.querySelector('#svg-base').innerHTML; this.svgBase = this.root.querySelector('#svg-base').innerHTML;
this.gaq = (typeof window._gaq === 'undefined') ? [] : window._gaq;
} }
keypressListener(event) { keypressListener(event) {
@ -79,7 +77,7 @@ export default class Regexper {
} }
_trackEvent(category, action) { _trackEvent(category, action) {
this.gaq.push(['_trackEvent', category, action]); window._gaq.push(['_trackEvent', category, action]);
} }
set state(state) { set state(state) {
@ -169,8 +167,9 @@ export default class Regexper {
if (message === 'Render cancelled') { if (message === 'Render cancelled') {
this._trackEvent('visualization', 'cancelled'); this._trackEvent('visualization', 'cancelled');
this.state = ''; this.state = '';
} else if (message.parseError) {
this._trackEvent('visualization', 'parse error');
} else { } else {
this._trackEvent('visualization', (message.parseError ? 'parse error' : 'exception'));
throw message; throw message;
} }
}) })