tagpro-game / tagpro-issues

Public repository to report and review TagPro bugs, enhancements and suggestions.
15 stars 4 forks source link

Catch errors in "tagpro.ready" #301

Open wilcooo opened 5 years ago

wilcooo commented 5 years ago

The function tagpro.ready that is widely used in userscripts doesn't catch errors. The problem: as soon as one function that is put into tagpro.ready( function ) throws an error, none of the functions that are added later are called back. Meaning that if one script throws an error inside a tagpro.ready callback, all scripts that are loaded later won't run, a bug which is very hard to catch.

1 line of code says more than a thousand words:

tagpro._readyCallbacks.forEach(function(e){e()});

should preferebly be

tagpro._readyCallbacks.forEach(function(e){
    try{e()}
    catch(error){console.error("Unhandled tagpro.ready() error. Mod makers, handle your errors!")}
});