If an error occurs while a command executes, Fireworks displays the unhelpful "An error occurred" dialog.
Always wrap your scripts in a try/catch block and then display a more useful error message in an alert dialog.
Some errors you encounter in your commands are JavaScript errors: you forgot to define a variable before using it, you have a typo in a method invocation, etc. The JS interpreter will throw an exception when it encounters such an error. If you don't catch the exception, Fireworks displays the generically unhelpful "An error occurred" dialog.
By wrapping your code in a try/catch block, you can catch the exception yourself and examine it for clues as to what went wrong:
try {
foo.bar();
} catch (exception) {
if (exception.lineNumber) {
alert([exception, exception.lineNumber, exception.fileName].join("\n"));
} else {
throw exception;
}
}
If you put that code in a .jsf file and run it, the alert will say something along the lines of "ReferenceError: foo is not defined", followed by the line number on which the code appeared and the filename. All of which is a lot more helpful than just saying that an error occurred.
Note the if statement in the catch block. It shows an alert dialog if the exception contains line number information. If it doesn't, it rethrows the exception. The reason for this was pointed out by the inimitable Aaron Beall. Exceptions that are triggered by the Fireworks API itself, like passing in the wrong number of parameters, don't include any information about the line number. The only thing the exception object contains is a negative number, like "-20303928", which is worse than useless. But if you rethrow the exception and let Fireworks itself handle it, the error dialog will display a somewhat more helpful message, like "Could not run the script. A parameter was incorrect".
Now, it would be a lot nicer if Fireworks would tell you which parameter is wrong and which line the error is on. But it's better than a negative number. To find the source of the error, you'll probably need to sprinkle some calls to alert() through your code to figure out where the bug occurs.
An alternative is to use my Fireworks Console extension. It provides a panel where you can see the output of calls to console.log(). You can pass any number of parameters to log(), and they'll be dumped into the console panel as pretty-printed strings. It's not as slick as Firebug, but it's a whole lot better than fiddling around with alerts. You can get the Fireworks Console extension here: http://bit.ly/9TqVZp
+