{"record":{"id":"ffdc6f385b65a209","repo":"jackwener/OpenCLI","slug":"text-must-not-be-empty","errorCode":null,"errorMessage":"text must not be empty","messagePattern":"text must not be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/utils.js","lineNumber":103,"sourceCode":"  const unique = Array.from(new Set(expanded));\n  if (unique.length === 0) {\n    throw new ArgumentError('--approve-kinds must contain at least one approval kind');\n  }\n  return unique;\n}\n\nexport function normalizeApprovalLimit(value, fallback = 1) {\n  const limit = value === undefined || value === null ? fallback : Number(value);\n  if (!Number.isInteger(limit) || limit < 1 || limit > 20) {\n    throw new ArgumentError('--limit must be an integer between 1 and 20');\n  }\n  return limit;\n}\n\nexport function ensurePrompt(text) {\n  const prompt = typeof text === 'string' ? text : '';\n  if (!prompt.trim()) {\n    throw new ArgumentError('text must not be empty');\n  }\n  return prompt;\n}\n\nexport function normalizeModelLabel(text) {\n  return String(text || '').toLowerCase().replace(/[^a-z0-9.]+/g, '');\n}\n\nexport function listOpenModelItemsScript() {\n  return `\n    (function() {\n      return Array.from(document.querySelectorAll('${TRAE_CN_MODEL_ITEM_SELECTOR}'))\n        .map((el, index) => ({\n          Index: index,\n          Model: String(el.innerText || el.textContent || '').replace(/\\\\s+/g, ' ').trim()\n        }))\n        .filter(item => item.Model);\n    })()","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/utils.js#L85-L121","documentation":"ensurePrompt coerces its argument to a string and requires non-whitespace content. The library throws this ArgumentError when the prompt text is empty or whitespace-only, because sending an empty prompt to Trae CN is meaningless.","triggerScenarios":"sendTraePrompt(page, '') or a prompt built from an empty template variable, a failed file read, or trimming that removed all content.","commonSituations":"Scripts passing unquoted empty shell variables, or prompts read from files that exist but are blank.","solutions":["Pass a non-empty prompt string with actual content","Check the variable/file feeding the prompt is populated","Trim and validate user input before calling the API"],"exampleFix":"// before\nawait sendTraePrompt(page, args.prompt || '');\n// after\nif (!args.prompt?.trim()) throw new Error('prompt required');\nawait sendTraePrompt(page, args.prompt);","handlingStrategy":"validation","validationCode":"if (typeof text !== 'string' || !text.trim()) throw new Error('prompt text must be a non-empty string');","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try { prompt = ensurePrompt(text); } catch (e) { if (/must not be empty/.test(e.message)) { console.error('Provide a non-empty prompt via --text or file'); process.exitCode = 2; } else throw e; }","preventionTips":["Check prompt source (file/arg/env) is populated before calling","Trim inputs early and fail with your own message","Avoid interpolating possibly-empty shell variables unvalidated"],"tags":["cli","argument-validation","empty-string"],"backgroundTag":"empty-required-parameter","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}