{"record":{"id":"38d521d8049ce101","repo":"jackwener/OpenCLI","slug":"collection-target-name-or-id-cannot-be-empty","errorCode":null,"errorMessage":"Collection target (name or id) cannot be empty","messagePattern":"Collection target \\(name or id\\) cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/collection-delete.js","lineNumber":22,"sourceCode":"    name: 'collection-delete',\n    access: 'write',\n    description: 'Delete an Instagram saved-posts collection (folder) by name or id',\n    domain: 'www.instagram.com',\n    args: [\n        {\n            name: 'target',\n            required: true,\n            positional: true,\n            help: 'Collection name (case-insensitive) or numeric collection_id',\n        },\n    ],\n    columns: ['status', 'collectionId', 'collectionName'],\n    pipeline: [\n        { navigate: 'https://www.instagram.com' },\n        { evaluate: `(async () => {\n  const target = \\${{ args.target | json }};\n  if (!target || !String(target).trim()) {\n    throw new Error('Collection target (name or id) cannot be empty');\n  }\n  const raw = String(target).trim();\n  const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';\n  if (!csrf) {\n    throw new Error('csrftoken cookie missing - make sure you are logged in to Instagram');\n  }\n  const headers = { 'X-IG-App-ID': '936619743392459' };\n\n  // Resolve name -> id via /collections/list/. Always go through this path so we can\n  // surface an explicit error on duplicate names or unknown names instead of relying\n  // on a 404.\n  const listRes = await fetch('https://www.instagram.com/api/v1/collections/list/?collection_types=%5B%22MEDIA%22%5D', {\n    credentials: 'include',\n    headers,\n  });\n  if (!listRes.ok) {\n    throw new Error('Failed to list collections: HTTP ' + listRes.status + ' - make sure you are logged in to Instagram');\n  }","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/collection-delete.js#L4-L40","documentation":"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.","triggerScenarios":"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 ''.","commonSituations":"Shell script where a variable failed to expand; user typed the command without the collection argument; upstream step produced an empty name.","solutions":["Pass a non-empty collection name or numeric collection_id","Check that the variable feeding the --target argument is populated","Quote arguments in the shell so spaces don't truncate them","Add a pre-check in your script that the target is non-empty before invoking"],"exampleFix":"// before\nnode collection-delete.js --target \"$NAME\"\n// after\n[ -n \"$NAME\" ] || { echo 'NAME is empty'; exit 1; }\nnode collection-delete.js --target \"$NAME\"","handlingStrategy":"validation","validationCode":"const target = process.argv[4] || '';\nif (!target || !target.trim()) throw new Error('collection-delete requires a non-empty --target');","typeGuard":"function isValidTarget(t: unknown): t is string {\n  return typeof t === 'string' && t.trim().length > 0;\n}","tryCatchPattern":"try {\n  await deleteCollection(target);\n} catch (e) {\n  if (String(e.message).includes('cannot be empty')) {\n    console.error('Usage: collection-delete.js --target <name|id>');\n    process.exit(2);\n  }\n  throw e;\n}","preventionTips":["Validate CLI args before invoking the pipeline","Quote shell variables so values don't collapse to empty","Check upstream steps actually produce a target value","Use a small arg-parsing helper that rejects empty required flags"],"tags":["validation","argument-error","input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}