Remote Debuging with an external Dat file

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Kukurykus, Tom, xbytor

Andrew

Remote Debuging with an external Dat file

Post by Andrew »

I have found it helpful to include remote debugging processes as an integral part of some of my larger scripts. These are designed to give me an easy to read synopsis of what happened when the script was run. The resulting dat file can emailed to me by the script user whenever anything goes wrong. There are three sets of reports written to the same dat file:

1. A copy of the users settings which allows me to recreate the dialog options they selected for that particular run.

2. A series of messages that track the script through it's internal processing eg:

opened /c/images/_MG001223.CR2
processed output layer 1
processed output layer 2
renamed to /c/images/040331-1646-01.CR2

opened /c/images/_MG001224.CR2
etc

3. The error message the is generated should the script fail.

The core 'write to debug file function' looks like this:


Code: Select all// trackdata is a string to be written to file
// myData.debugFile is a File Object pointing to the debug file

function fDebug (trackdata, myData)
{
   var fp;
   fp = myData.debugFile;
   fp.open('e');
   fp.seek(0,2);
   if (fp.write(trackdata)) fp.close();
   else Window.alert("Error saving debug data");
}

Writing to it is as easy as this:

Code: Select alldebugString = '\n\nFile ' + myImageReference + ' Opened OK ';fDebug (debugString, myData);


All my scripts which use dialogs have their own routines for capturing the 'this run' dialog settings. I use that to write the settings as a string (trackdata) to the file first.

I follow this by a couple of new-lines, and '/*'. I later make sure '*/' is written at the end of the data file. This means I can use my debug file to read settings straight into my script and automatically reload the user's settings that caused the problem without any of the debug report information being read in as data (because it is hidden within a Javascript comment..

I use catch to write any error message to the file if an error occurs. I use finally to write the final '*/' at the end of the debug file.

One possible modification would be to open the debug file at the beginnign of the script and to leave it open, rather than opening and closing each time as I do here.

Andrew

Andrew

Remote Debuging with an external Dat file

Post by Andrew »

Following on from my post about the Error Object, I will in future attempt to catch the error line number as follows:

Code: Select allcatch (e) {
   var ln = '';
   if (typeof e == 'object' && e.ln != undefined) ln =  '\n\nLine: ' +  e.line + '\n\n';
   debugString = ln + e;fDebug (debugString, myData);
}


Andrew

Mike Hale

Remote Debuging with an external Dat file

Post by Mike Hale »

You may have already thought of this, I've just started thinking about error logging.

You could call a function inside the catch statement that has a prompt or dialog asking the user for info you think might be useful that is not part of the error. You could use the error type to skip asking some types of errors.

Or have I just not thought this through?

Andrew

Remote Debuging with an external Dat file

Post by Andrew »

"prompt or dialog asking the user for info"

That's a good idea.

Andrew