Motivation
- Catches all exceptions thrown in JavaScript.
- Catch errors where they originate from.
- Ability to log, and send errors to a server while alpha testing.
- Insipired by proxino, and node.js's
uncaughtException
event. - Identify where try/catch blocks are used where they shouldn't be.
Features
- Wrapped scripts are cached until they're modified.
- Connect Middleware
- beanpoll Plugin
- Works with mesh
Super Important Note
All functions are wrapped in try-catch blocks, so it would be a terrible idea to use this for production code.
Example
Create a file called script.js
:
//only catch all if functions have been wrapped aroundiftypeof catchall != 'undefined' //on catch all, send error to server catchall { console; console; } { ;} ;
In terminal, type:
catchall -i ./script.js -o ./script.guarded.jsnode ./script.guarded.js
The message you should see is:
An error has occurred!
unknownFunction is not defined
Command Line Usage
Usage: -i [input_js] Options: -i, --input input js file or url [required] -o, --output output js file
Connect Middleware
var catchall = connect = app = connect; app;app;app;
Here's how you'd use catchall in html:
<!-- from remote url --> <!-- from local server -->
API
catchall.wrap(source[, ops], callback)
Generates guarded code where all exceptions are caught.
source
- the javascript source to wrap aroundops
- the wrap optionsadd_handler
- add the handler at the head of the script (catchall.onerror = function(){}
)uglify
- uglify the script by removing all whitespaceindent_level
- indentation in spaces
Here's a simple example:
var catchall = ; catchall;
The above script will produce:
{ try ; catche catchall; }
catchall.load(source[, ops], callback)
Loads the given source, and wraps around it. Can be from fs, or url.
Example:
catchall; catchall;