{"record":{"id":"6cadbb1de16af955","repo":"jackwener/OpenCLI","slug":"weibo-delete-id-cannot-be-empty","errorCode":null,"errorMessage":"weibo delete: id cannot be empty","messagePattern":"weibo delete: id cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weibo/delete.js","lineNumber":14,"sourceCode":"/**\n * Weibo delete — remove a single post owned by the logged-in user.\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { requireObjectEvaluateResult, unwrapEvaluateResult } from './utils.js';\n\nconst WEIBO_HOST_RE = /(^|\\.)weibo\\.(com|cn)$/i;\nconst POST_ID_RE = /^[A-Za-z0-9]{4,32}$/;\n\nfunction normalizePostId(raw) {\n    const input = String(raw ?? '').trim();\n    if (!input) {\n        throw new ArgumentError('weibo delete: id cannot be empty');\n    }\n\n    let candidate = input;\n    try {\n        const url = new URL(input);\n        if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n            throw new ArgumentError('weibo delete: URL must use http or https');\n        }\n        if (!WEIBO_HOST_RE.test(url.hostname)) {\n            throw new ArgumentError('weibo delete: URL must be a weibo.com or weibo.cn post URL');\n        }\n        const parts = url.pathname.split('/').filter(Boolean);\n        if (url.hostname.toLowerCase().endsWith('weibo.cn') && parts[0] === 'status') {\n            candidate = parts[1] ?? '';\n        } else {\n            candidate = parts.at(-1) ?? '';\n        }\n    } catch (error) {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/delete.js#L1-L32","documentation":"normalizePostId validates the id argument for the weibo delete command. If the raw input trims to an empty string, there is nothing to normalize or resolve, so it throws ArgumentError immediately before any URL parsing.","triggerScenarios":"Calling `weibo delete` with no --id value, an --id of \"\" or whitespace, or passing kwargs.id as null/undefined from a script that failed to capture the id from a previous command's output.","commonSituations":"Shell variable interpolation producing an empty string (e.g. $POST_ID unset), copy-paste losing the id, or a wrapper script forwarding a null id from upstream JSON.","solutions":["Pass a valid id: numeric idstr, mblogid, or a weibo.com/cn post URL, e.g. weibo delete --id 5012345678901","Check the shell variable holding the id is actually set (echo \"$POST_ID\") before invoking the CLI","Copy the id from `weibo me` or `weibo post` output columns (id / mblogid) rather than retyping it"],"exampleFix":"// before\nweibo delete --id \"$POST_ID\"\n// after\n: \"${POST_ID:?POST_ID is not set}\"\nweibo delete --id \"$POST_ID\"","handlingStrategy":"validation","validationCode":"function isValidDeleteArg(id) {\n  return typeof id === 'string' && id.trim().length > 0;\n}\nif (!isValidDeleteArg(process.env.POST_ID)) throw new Error('POST_ID is empty');","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await cliDelete({ id: rawId });\n} catch (err) {\n  if (err instanceof ArgumentError && /id cannot be empty/.test(err.message)) {\n    throw new Error('Provide --id: numeric idstr, mblogid, or weibo post URL');\n  } else throw err;\n}","preventionTips":["Always pass --id explicitly; never rely on unset shell variables","Use ${VAR:?msg} guards for interpolated ids in scripts","Copy ids from `weibo me`/`weibo post` output columns","Trim inputs before passing to the CLI"],"tags":["weibo","argument-validation","cli"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}