jackwener/OpenCLI · error · ArgumentError
xiaohongshu/delete-note: note-id cannot be empty
Error message
xiaohongshu/delete-note: note-id cannot be empty
What it means
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.
Source
Thrown at clis/xiaohongshu/delete-note.js:60
function requireActionResult(payload, context) {
const result = requireEvaluateObject(payload, context);
if (typeof result.ok !== 'boolean') {
throw new CommandExecutionError(`xiaohongshu/delete-note: malformed ${context} payload`);
}
return result;
}
function isXiaohongshuHost(hostname) {
const host = String(hostname || '').toLowerCase();
return host === 'xiaohongshu.com' || host.endsWith('.xiaohongshu.com');
}
function isSupportedQueryNoteUrl(url) {
return url.hostname.toLowerCase() === 'creator.xiaohongshu.com'
&& url.pathname.replace(/\/+$/, '') === '/statistics/note-detail';
}
function normalizeNoteId(input) {
const raw = String(input ?? '').trim();
if (!raw) {
throw new ArgumentError('xiaohongshu/delete-note: note-id cannot be empty');
}
if (NOTE_ID_RE.test(raw))
return raw.toLowerCase();
if (!/^https:\/\//i.test(raw)) {
throw new ArgumentError('xiaohongshu/delete-note: note-id must be a 24-character Xiaohongshu note ID or an exact Xiaohongshu note URL');
}
let url;
try {
url = new URL(raw);
}
catch {
throw new ArgumentError('xiaohongshu/delete-note: invalid note URL');
}
if (url.protocol !== 'https:' || url.username || url.password || url.port || !isXiaohongshuHost(url.hostname)) {
throw new ArgumentError('xiaohongshu/delete-note: note URL must be an exact https://*.xiaohongshu.com URL');
}
const queryId = url.searchParams.get('noteId') || url.searchParams.get('note_id');
if (queryId && NOTE_ID_RE.test(queryId) && isSupportedQueryNoteUrl(url))View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
run(['clis/xiaohongshu/delete-note.js', '--note-id', noteId]); // noteId was ''
// after
if (!noteId || !noteId.trim()) throw new Error('note-id is required');
run(['clis/xiaohongshu/delete-note.js', '--note-id', noteId.trim()]); Defensive patterns
Strategy: validation
Validate before calling
function isValidNoteIdArg(v) {
const s = String(v ?? '').trim();
return s.length > 0;
}
if (!isValidNoteIdArg(noteId)) throw new Error('note-id is required'); Type guard
function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try {
await deleteNote({ noteId });
} catch (e) {
if (e instanceof ArgumentError && /note-id cannot be empty/.test(e.message)) {
// surface a clear CLI usage message and exit
} else { throw e; }
} Prevention
- 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
When it happens
Trigger: Invoking xiaohongshu/delete-note with the note-id missing, set to an empty string, or containing only whitespace (String(input).trim() yields '').
Common situations: Forgetting the note-id flag on the command line; a shell variable that was unset/empty; an upstream script passing undefined into the command.
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
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6413d70d5d887fed.
Report an issue: GitHub.