A Twitter user has been having some problems with silent errors, which are indeed a complete pain in the ass. My experience of silent errors has been only when running erroneous scripts via fl.runScript();
I do want as part of the framework have some kind of functionality that tackles this somehow, and this is my first test.
It's a function that attempts to eval the contents of the passed uri, then will print any error messages (instead of failing), then finally will run the uri directly using an undocumented method of FLfile to get the actual line number of the error (but this could be erroneous itself if a nested script relies on scoped variables that may already be disposed of).
fl.tryScript = function(uri)
{
// if the file exists, test it
if(FLfile.exists(uri))
{
// grab the passed-in file contents
var path = '"' + FLfile.uriToPlatformPath(uri) + '"';
fl.trace('Testing: ' + path);
var jsfl = FLfile.read(uri);
// attempt to eval the JSFL
try
{
eval(jsfl);
}
// if it fails, print the error, then run the file standalone
catch(err)
{
fl.trace(err);
fl.trace('Running: ' + path);
var exec = fl.version.match(/\bMAC\b/i) ? 'exec ' + path : path;
FLfile.runCommandLine(exec);
}
}
// Let the user know the file doesn't exist
else
{
fl.trace('Error: uri not found: ' + uri);
};
}
var uri = 'file:///C|/temp/jsfl/bad-file.jsfl'
fl.tryScript(uri);
Comments welcome.