Photoshop Generator Node Plugins and Error Handling

At Blink Inc we have been writing Photoshop plugins that use their new-ish ‘Generator‘ Node-based plugin technology.  We use some of these plugins to process images in real-time from our photo studio.

The Generator technology makes writing PS plugins a lot more pleasant than using the other alternatives Adobe has developed in the past however there are some gotchas involved around the requirement to use the older JSX code to invoke PS actions from Node. Hopefully Adobe continues to develop and support their node framework for plugins so this gets more tightly integrated.

The main problem with the way plugins work has to do with a common Javascript issue – uncaught exceptions.  It turns out that the code you pass to Photoshop using

evaluateJSXString(...)

is not wrapped in a try-catch block by default! This *will* cause you maddening debugging sessions where your code will mysteriously not function, or will appear to not return from a call.

In addition, exceptions from the JSX interpreter are *not* passed back from the

evaluateJSXString(...)

call, so we strongly recommend you make sure to wrap your JSX code in a try / catch block. All of the JSX code we pass to the JSX interpreter is wrapped in:

 try {

   // Your JSX code goes here

   result = callYourProcessingCodeWithAFunction();
 } catch (e) {
   result = e;
 }

Since we do a lot of file manipulation in PS this can be used to at least diagnose what went wrong during testing or in production via logging.  Since you can get a result object back from the JSX interpreter, you can use this to return the result of your operation (usually a string if success) or return the error object you get if an exception gets thrown.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s