Parsing "Error: invalid argument"

I have a button which merges layers (as a test) and I’ve put it inside a try/catch block to investigate what happens:

async function mergeSelectedLayers() {
  const batchCommands = [eventMergeLayers];
  try {
    return await executeAsModal(batchPlay(batchCommands, {}), { commandName: "Merge Selected Layers" });
  } catch (e) {


const eventMergeLayers = {
  "_obj": "mergeLayersNew",
  "_isCommand": true

is the event descriptor for a layer merge, via Alchemist.

I am getting “Error: invalid argument” but the merging of the layers still occurs. The argument is generic enough that it’s tough to figure out where it’s coming from. What’s spitting out the error? It may give me some insight into why certain action descriptors fail to play.

Try changing to

    return await executeAsModal(() => batchPlay(batchCommands, {}), { commandName: "Merge Selected Layers" });

You need to pass a function to exeModal and not just some result of any type

Thanks for this information! That makes sense. What’s being passed in the first argument is, thus, an object describing the function, and not an evaluation of the function itself.