{"record":{"id":"e74dae16e4dc9aa8","repo":"jackwener/OpenCLI","slug":"collection-not-found-raw-available-names","errorCode":null,"errorMessage":"Collection not found: ${raw}. Available: ${(names.length ? names.join(', ') : '(none)')}","messagePattern":"Collection not found: (.+?)\\. Available: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/collection-delete.js","lineNumber":58,"sourceCode":"  }\n  const listData = await listRes.json();\n  const collections = listData?.items || [];\n  const isNumericId = /^\\\\d{6,}$/.test(raw);\n  let id = '';\n  let resolvedName = '';\n  if (isNumericId) {\n    const hit = collections.find((c) => String(c?.collection_id) === raw);\n    if (!hit) {\n      throw new Error('Collection id not found in your account: ' + raw);\n    }\n    id = String(hit.collection_id);\n    resolvedName = String(hit.collection_name || '');\n  } else {\n    const wanted = raw.toLowerCase();\n    const matches = collections.filter((c) => String(c?.collection_name || '').trim().toLowerCase() === wanted);\n    if (matches.length === 0) {\n      const names = collections.map((c) => c?.collection_name).filter(Boolean);\n      throw new Error('Collection not found: ' + raw + '. Available: ' + (names.length ? names.join(', ') : '(none)'));\n    }\n    if (matches.length > 1) {\n      const ids = matches.map((c) => c.collection_id).join(', ');\n      throw new Error('Multiple collections share the name \"' + raw + '\" (ids: ' + ids + '). Pass the numeric collection_id explicitly to disambiguate.');\n    }\n    id = String(matches[0].collection_id);\n    resolvedName = String(matches[0].collection_name || raw);\n  }\n\n  const fd = new FormData();\n  fd.append('module_name', 'collection_settings');\n  const res = await fetch('https://www.instagram.com/api/v1/collections/' + encodeURIComponent(id) + '/delete/', {\n    method: 'POST',\n    credentials: 'include',\n    headers: { ...headers, 'X-CSRFToken': csrf },\n    body: fd,\n  });\n  if (!res.ok) {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/collection-delete.js#L40-L76","documentation":"Thrown when the target is treated as a name (non-numeric) and no collection in the account matches that exact name case-insensitively after trimming. The error helpfully lists available collection names so the caller can correct the target without a separate list call.","triggerScenarios":"Deleting by a name that doesn't exactly match — typos, extra punctuation, trailing whitespace differences beyond trim, renamed collections, or deleting a name that was already removed.","commonSituations":"Collections renamed in the UI since the script was written; case/character mismatches (emoji, accents); automation assuming a collection the user never created.","solutions":["Use one of the names shown in the 'Available:' list, exactly","Or pass the numeric collection_id instead of a name","Re-list collections to see current names before retrying","Fix typos or invisible characters in your configured target name"],"exampleFix":"// before\nnode collection-delete.js --target \"MyCollction\" // typo\n// after\nnode collection-delete.js --target \"My Collection\" // exact available name","handlingStrategy":"validation","validationCode":"const list = await listCollections();\nconst match = list.find((c) => c.collection_name.trim().toLowerCase() === targetName.toLowerCase());\nif (!match) throw new Error('No such collection: ' + targetName + ' Available: ' + list.map((c) => c.collection_name).join(', '));","typeGuard":"function hasExactName(name: string, collections: {collection_name: string}[]): boolean {\n  const w = name.trim().toLowerCase();\n  return collections.some((c) => c.collection_name.trim().toLowerCase() === w);\n}","tryCatchPattern":"try {\n  await deleteCollection(name);\n} catch (e) {\n  if (String(e.message).startsWith('Collection not found')) {\n    console.error(e.message); // lists available names\n    return;\n  }\n  throw e;\n}","preventionTips":["Copy collection names exactly (watch emoji/accents/trailing spaces)","Prefer numeric collection_id over names in scripts","Re-list collections after any manual renames","Normalize name matching (trim + lowercase) in your own pre-checks"],"tags":["validation","id-resolution","instagram-api"],"backgroundTag":"entity-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}