{"record":{"id":"b6e84ad018e2fdd6","repo":"jackwener/OpenCLI","slug":"label-cannot-be-empty-b6e84a","errorCode":null,"errorMessage":"${label} cannot be empty","messagePattern":"(.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/xianyu/im.js","lineNumber":37,"sourceCode":"}\n\nexport function normalizeRank(value) {\n    const raw = String(value ?? '').trim();\n    if (!raw) return 0;\n    if (!/^\\d+$/.test(raw)) {\n        throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');\n    }\n    const n = Number(raw);\n    if (!Number.isSafeInteger(n) || n < 1) {\n        throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');\n    }\n    return n;\n}\n\nexport function requireText(value, label) {\n    const text = String(value ?? '').replace(/\\s+/g, ' ').trim();\n    if (!text) {\n        throw new ArgumentError(`${label} cannot be empty`);\n    }\n    return text;\n}\n\nexport function requireEvaluateObject(payload, label) {\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError(`Xianyu ${label} returned malformed browser payload`);\n    }\n    return payload;\n}\n\nexport function requireClickResult(payload, label) {\n    const result = requireEvaluateObject(payload, label);\n    if (result.ok !== true) {\n        throw new CommandExecutionError(`Xianyu ${label} failed: ${result.reason || 'unknown-reason'}`);\n    }\n    return result;\n}","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/im.js#L19-L55","documentation":"requireText normalizes a string parameter (collapsing whitespace, trimming) and throws ArgumentError when the result is empty. It guards xianyu commands that need non-empty text (e.g. message content, peer identifiers).","triggerScenarios":"Calling a xianyu command with text='' , text='   ', text=null, or text='\\n\\t' — anything that trims to the empty string.","commonSituations":"Empty message body from an upstream template; whitespace-only user input; null passed instead of a default; placeholder never substituted.","solutions":["Provide a non-empty string for the labeled parameter","Trim/validate input before calling the command","Prompt the user again when input is blank","Add a guard: if (!text?.trim()) skip or error early in your code"],"exampleFix":"// before\nawait xianyuSend({ text: userInput }); // throws when blank\n// after\nconst text = (userInput ?? '').trim();\nif (!text) throw new Error('message text required');\nawait xianyuSend({ text });","handlingStrategy":"validation","validationCode":"const text = String(value ?? '').replace(/\\s+/g, ' ').trim();\nif (!text) throw new Error(`${label} cannot be empty`);","typeGuard":"function isNonEmptyText(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await xianyuSend({ text });\n} catch (e) {\n  if (e?.name === 'ArgumentError' && /cannot be empty/.test(e.message)) {\n    throw new Error('please provide a message body');\n  }\n  throw e;\n}","preventionTips":["Trim and check input before calling","Never pass null/undefined where text is required","Re-prompt users for blank message bodies"],"tags":["validation","argument-error","xianyu"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}