Skip to content

Instantly share code, notes, and snippets.

@arantius
Created August 18, 2011 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arantius/1154205 to your computer and use it in GitHub Desktop.
Save arantius/1154205 to your computer and use it in GitHub Desktop.
Test the way that various errors are reported in user scripts.
// ==UserScript==
// @name Error-izer
// @namespace https://github.com/arantius
// @description Cause all sorts of different errors. One at a time.
// @include http*
// @unwrap
// ==/UserScript==
var errorId = GM_getValue('errorId', 1);
errorId++;
GM_setValue('errorId', errorId);
function makeProblems() {
dump('Triggerring error (' + errorId + '), kind: ');
switch (errorId) {
case 1:
dump('null dereference.\n');
null.property;
break;
case 2:
dump('call null.\n');
null();
break;
case 3:
dump('call undefined.\n');
undefined();
break;
case 4:
//dump('document.write "Security error" (FF3).\n');
//document.write('');
break;
case 5:
dump('thrown.\n');
throw new Error('foo');
break;
case 6:
dump('override global.\n');
eval('var sidebar;');
break;
case 7:
dump('syntax.\n');
eval('for(1;2;)');
break;
default:
dump('unknown. Resetting for next run.\n');
GM_setValue('errorId', 0);
break;
}
}
setTimeout(makeProblems, 0);
// This one causes a compile time error, regardless of position, when @unwrap:
//var sidebar;
// Syntax errors also happen at compile time:
//for (a;b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment