{"record":{"id":"6413d70d5d887fed","repo":"jackwener/OpenCLI","slug":"xiaohongshu-delete-note-note-id-cannot-be-empty","errorCode":null,"errorMessage":"xiaohongshu/delete-note: note-id cannot be empty","messagePattern":"xiaohongshu/delete-note: note-id cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/delete-note.js","lineNumber":60,"sourceCode":"function requireActionResult(payload, context) {\n    const result = requireEvaluateObject(payload, context);\n    if (typeof result.ok !== 'boolean') {\n        throw new CommandExecutionError(`xiaohongshu/delete-note: malformed ${context} payload`);\n    }\n    return result;\n}\nfunction isXiaohongshuHost(hostname) {\n    const host = String(hostname || '').toLowerCase();\n    return host === 'xiaohongshu.com' || host.endsWith('.xiaohongshu.com');\n}\nfunction isSupportedQueryNoteUrl(url) {\n    return url.hostname.toLowerCase() === 'creator.xiaohongshu.com'\n        && url.pathname.replace(/\\/+$/, '') === '/statistics/note-detail';\n}\nfunction normalizeNoteId(input) {\n    const raw = String(input ?? '').trim();\n    if (!raw) {\n        throw new ArgumentError('xiaohongshu/delete-note: note-id cannot be empty');\n    }\n    if (NOTE_ID_RE.test(raw))\n        return raw.toLowerCase();\n    if (!/^https:\\/\\//i.test(raw)) {\n        throw new ArgumentError('xiaohongshu/delete-note: note-id must be a 24-character Xiaohongshu note ID or an exact Xiaohongshu note URL');\n    }\n    let url;\n    try {\n        url = new URL(raw);\n    }\n    catch {\n        throw new ArgumentError('xiaohongshu/delete-note: invalid note URL');\n    }\n    if (url.protocol !== 'https:' || url.username || url.password || url.port || !isXiaohongshuHost(url.hostname)) {\n        throw new ArgumentError('xiaohongshu/delete-note: note URL must be an exact https://*.xiaohongshu.com URL');\n    }\n    const queryId = url.searchParams.get('noteId') || url.searchParams.get('note_id');\n    if (queryId && NOTE_ID_RE.test(queryId) && isSupportedQueryNoteUrl(url))","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/delete-note.js#L42-L78","documentation":"normalizeNoteId rejects an empty note-id argument with an ArgumentError. The CLI needs either a 24-hex-character Xiaohongshu note ID or an exact note URL; an empty/whitespace-only value cannot identify any note to delete. This is an upfront input validation guard.","triggerScenarios":"Invoking xiaohongshu/delete-note with the note-id missing, set to an empty string, or containing only whitespace (String(input).trim() yields '').","commonSituations":"Forgetting the note-id flag on the command line; a shell variable that was unset/empty; an upstream script passing undefined into the command.","solutions":["Pass a valid note ID (24 hex characters) or a full https note URL via the note-id argument","Check the shell variable holding the ID is actually set and non-empty (`echo \"$NOTE_ID\"`)","Extract the ID from the note URL if you only have a link","Fail fast in calling scripts: validate the argument before invoking the command"],"exampleFix":"// before\nrun(['clis/xiaohongshu/delete-note.js', '--note-id', noteId]); // noteId was ''\n// after\nif (!noteId || !noteId.trim()) throw new Error('note-id is required');\nrun(['clis/xiaohongshu/delete-note.js', '--note-id', noteId.trim()]);","handlingStrategy":"validation","validationCode":"function isValidNoteIdArg(v) {\n  const s = String(v ?? '').trim();\n  return s.length > 0;\n}\nif (!isValidNoteIdArg(noteId)) throw new Error('note-id is required');","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  await deleteNote({ noteId });\n} catch (e) {\n  if (e instanceof ArgumentError && /note-id cannot be empty/.test(e.message)) {\n    // surface a clear CLI usage message and exit\n  } else { throw e; }\n}","preventionTips":["Always pass note-id explicitly; never rely on possibly-unset env/shell variables","Trim inputs before passing them to the command","Add a pre-flight check in scripts that compose the command programmatically"],"tags":["argument-validation","input-validation","cli"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}