Why this error number? (8007)

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

undavide

Why this error number? (8007)

Post by undavide »

Hello,
if I try to remove a Layer Mask from a layer that doesn't have one I obviously get an error.
I find puzzling why the error message is different whether the layer is bitmap or an adjustment layer.

Case A - Layer Mask on a bitmap layer
Create a new document (RGB, 8bit, white just to be simple).
Duplicate the background layer and run the script you find at the end.
Error message: "General Photoshop error occurred. This functionality may not be available in this version of Photoshop. The command “Delete” is not currently available."
Error number: 25920

Case B - Layer Mask on an Adjustment Layer
Create a new document (RGB, 8bit, white just to be simple).
Create a new adjustment layer (no matter which kind) and remove if present the layer mask. Run the script.
Error message: "User cancelled the operation."
Error number: 8007

I went crazy trying to debug that 8007 (which is the ESC keypress) - I wonder why the heck it shows up there. The Case A error makes totally sense, shouldn't be the same in Case B as well?!
Thank you for your help!

Davide

Code: Select allvar s2t = function(stringID) {
  return app.stringIDToTypeID(stringID);
};

// Delete a Layer Mask
var deleteLayerMask = function(layer) {
  var d, layerName, r;
  layerName = (layer != null ? layer.name : app.activeDocument.activeLayer.name);
  d = new ActionDescriptor();
  r = new ActionReference();
  r.putEnumerated(s2t('channel'), s2t('channel'), s2t('mask'));
  r.putName(s2t('layer'), layerName);
  d.putReference(s2t('target'), r);
  return executeAction(s2t('delete'), d, DialogModes.NO);
};

try {
    deleteLayerMask ();
} catch(e) {
    alert(e.message + "\n" + e.number);
}

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

xbytor

Why this error number? (8007)

Post by xbytor »

The simple fact is that PS throws an 8007 in some contexts where it should be throwing something else. I've also seen cases where an 8007 pops up where there really wasn't an error. Retrying the operation would sometimes fix the problem, as seen in this chunk of code:
Code: Select all  try {
    layer.resize(100, 100, AnchorPosition.MIDDLECENTER);

  } catch (e) {
    if (e.number == 8007) {      // User cancelled
      try {
        layer.resize(100, 100, AnchorPosition.MIDDLECENTER);
      } catch (e) {
        if (e.number != 8007) {      // User cancelled
          Error.runtimeError(9001, e.toString());
        }
      }
    } else {
      Error.runtimeError(9001, e.toString());
    }
  }
undavide

Why this error number? (8007)

Post by undavide »

Thanks X,
that sounds really weird

Davide
xbytor

Why this error number? (8007)

Post by xbytor »

undavide wrote:that sounds really weird

Definitely. I've only ran across it in a couple of cases, so it's not that common.