jackwener/OpenCLI · error

Collection target (name or id) cannot be empty

Error message

Collection target (name or id) cannot be empty

What it means

Thrown inside the collection-delete browser evaluation when the target argument (collection name or numeric id) is empty or whitespace-only. It is a fail-fast input validation guard before any cookie lookup or network request. The delete pipeline requires an unambiguous target to resolve.

Source

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

    name: 'collection-delete',
    access: 'write',
    description: 'Delete an Instagram saved-posts collection (folder) by name or id',
    domain: 'www.instagram.com',
    args: [
        {
            name: 'target',
            required: true,
            positional: true,
            help: 'Collection name (case-insensitive) or numeric collection_id',
        },
    ],
    columns: ['status', 'collectionId', 'collectionName'],
    pipeline: [
        { navigate: 'https://www.instagram.com' },
        { evaluate: `(async () => {
  const target = \${{ args.target | json }};
  if (!target || !String(target).trim()) {
    throw new Error('Collection target (name or id) cannot be empty');
  }
  const raw = String(target).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 headers = { 'X-IG-App-ID': '936619743392459' };

  // Resolve name -> id via /collections/list/. Always go through this path so we can
  // surface an explicit error on duplicate names or unknown names instead of relying
  // on a 404.
  const listRes = await fetch('https://www.instagram.com/api/v1/collections/list/?collection_types=%5B%22MEDIA%22%5D', {
    credentials: 'include',
    headers,
  });
  if (!listRes.ok) {
    throw new Error('Failed to list collections: HTTP ' + listRes.status + ' - make sure you are logged in to Instagram');
  }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty collection name or numeric collection_id
  2. Check that the variable feeding the --target argument is populated
  3. Quote arguments in the shell so spaces don't truncate them
  4. Add a pre-check in your script that the target is non-empty before invoking

Example fix

// before
node collection-delete.js --target "$NAME"
// after
[ -n "$NAME" ] || { echo 'NAME is empty'; exit 1; }
node collection-delete.js --target "$NAME"
Defensive patterns

Strategy: validation

Validate before calling

const target = process.argv[4] || '';
if (!target || !target.trim()) throw new Error('collection-delete requires a non-empty --target');

Type guard

function isValidTarget(t: unknown): t is string {
  return typeof t === 'string' && t.trim().length > 0;
}

Try / catch

try {
  await deleteCollection(target);
} catch (e) {
  if (String(e.message).includes('cannot be empty')) {
    console.error('Usage: collection-delete.js --target <name|id>');
    process.exit(2);
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking collection-delete with an empty string, null, or whitespace target — e.g. a CLI flag not passed, an empty variable, or template args interpolation producing ''.

Common situations: Shell script where a variable failed to expand; user typed the command without the collection argument; upstream step produced an empty name.

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/38d521d8049ce101. Report an issue: GitHub.