jackwener/OpenCLI · error

Collection name cannot be empty

Error message

Collection name cannot be empty

What it means

Validation thrown inside the in-page collection-create pipeline when the provided --name argument is empty, whitespace-only, or otherwise falsy after the template substitution. Instagram requires a non-empty name for a new collection, so the CLI guards this before sending any request. It is a pure input-validation error — no network call has been made yet.

Source

Thrown at clis/instagram/collection-create.js:22

    name: 'collection-create',
    access: 'write',
    description: 'Create a new Instagram saved-posts collection (folder)',
    domain: 'www.instagram.com',
    args: [
        {
            name: 'name',
            required: true,
            positional: true,
            help: 'Name of the collection to create',
        },
    ],
    columns: ['status', 'collectionId', 'collectionName', 'mediaCount'],
    pipeline: [
        { navigate: 'https://www.instagram.com' },
        { evaluate: `(async () => {
  const name = \${{ args.name | json }};
  if (!name || !String(name).trim()) {
    throw new Error('Collection name cannot be empty');
  }
  const trimmed = String(name).trim();
  const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
  if (!csrf) {
    throw new Error('csrftoken cookie missing - make sure you are logged in to Instagram');
  }
  const fd = new FormData();
  fd.append('name', trimmed);
  fd.append('module_name', 'collection_create');
  const res = await fetch('https://www.instagram.com/api/v1/collections/create/', {
    method: 'POST',
    credentials: 'include',
    headers: {
      'X-IG-App-ID': '936619743392459',
      'X-CSRFToken': csrf,
    },
    body: fd,
  });

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty name: collection-create --name "My Collection"
  2. Check the shell variable is actually set: echo "$NAME" before invoking
  3. Quote arguments containing spaces to avoid shell word-splitting eating them
  4. Add a pre-check in scripts calling the CLI to fail fast on empty names

Example fix

// before
const name = process.env.COLLECTION_NAME; // may be undefined
await run(['instagram', 'collection-create', '--name', name]);

// after
const name = (process.env.COLLECTION_NAME || '').trim();
if (!name) throw new Error('COLLECTION_NAME is required');
await run(['instagram', 'collection-create', '--name', name]);
Defensive patterns

Strategy: validation

Validate before calling

function requireNonEmptyName(name) {
  const trimmed = String(name ?? '').trim();
  if (!trimmed) throw new Error('Collection name cannot be empty');
  return trimmed;
}
const name = requireNonEmptyName(process.env.COLLECTION_NAME);

Type guard

function isValidCollectionName(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await createInstagramCollection(name);
} catch (e) {
  if (e.message === 'Collection name cannot be empty') {
    console.error('Provide a --name value, e.g. --name "Saved Recipes"');
    process.exitCode = 2;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the collection-create command with an empty or missing name argument, e.g. `collection-create ''` or omitting --name so the `args.name | json` substitution yields '' or null.

Common situations: Shell variable holding the name is unset/empty (e.g. $NAME not defined); quoting mistakes causing the name to be dropped; programmatic invocation passing an empty string; copy-paste losing the argument.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/756326da05fbeac8. Report an issue: GitHub.