{"record":{"id":"0e919387ccfe1199","repo":"jackwener/OpenCLI","slug":"query-is-required-0e9193","errorCode":null,"errorMessage":"query is required","messagePattern":"query is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/ask.js","lineNumber":359,"sourceCode":"            warning: sourceError,\n            message_id: msgId,\n            conversation_id: conversationId,\n          };\n        } catch (err) {\n          return {\n            ok: false,\n            error: String(err?.message || err || 'unknown_error'),\n            stack: String(err?.stack || '').slice(0, 1500),\n            page_url: location.href,\n          };\n        }\n      })()\n    `;\n}\n\nfunction requirePrompt(query) {\n    const prompt = String(query || '').trim();\n    if (!prompt) throw new ArgumentError('query is required');\n    return prompt;\n}\n\nfunction mapAskError(raw, timeoutSeconds) {\n    const error = compactSingleLine(raw?.error);\n    if (error === 'answer_timeout') {\n        throw new TimeoutError('xiaohongshu ask', timeoutSeconds, '点点没有在超时时间内返回答案；可以重试或提高 --timeout。');\n    }\n    if (error === 'send_message_failed') {\n        throw new AuthRequiredError(XHS_WEB_HOST, 'Xiaohongshu 点点 did not accept the query. Check login status for www.xiaohongshu.com.');\n    }\n    throw new CommandExecutionError(\n        `xiaohongshu ask failed: ${error || 'unknown error'}`,\n        raw?.page_url ? `Page URL: ${raw.page_url}` : undefined,\n    );\n}\n\nfunction requireAskPayload(raw) {","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/ask.js#L341-L377","documentation":"requirePrompt normalizes the query argument of `xiaohongshu ask`; after String-coercion and trimming, an empty/absent query throws this ArgumentError. The command needs a non-empty natural-language question to send to 点点, so it fails fast rather than launching a browser session with nothing to ask.","triggerScenarios":"Running `opencli xiaohongshu ask` with no positional query, with an empty string '', or with only whitespace like \"   \"; also query values that are null/undefined from a wrapper script.","commonSituations":"Shell variable expansion yielding an empty value ($Q unset with set -u not enabled); pipes/args mis-ordered so the question never reaches the command; copy-paste losing the quoted argument.","solutions":["Pass a non-empty quoted query: opencli xiaohongshu ask \"how to X\"","Check the shell variable holding the question is actually set and non-blank","Quote the argument so leading/trailing spaces or special chars are preserved","In wrapper scripts, validate the prompt before invoking the CLI"],"exampleFix":"// before\nopencli xiaohongshu ask \"$QUERY\"   # QUERY is empty\n// after\n[ -n \"$QUERY\" ] && opencli xiaohongshu ask \"$QUERY\"","handlingStrategy":"validation","validationCode":"const prompt = String(process.argv[3] ?? '').trim();\nif (!prompt) {\n  console.error('usage: opencli xiaohongshu ask \"<question>\"');\n  process.exit(2);\n}","typeGuard":"function hasPrompt(q) {\n  return typeof q === 'string' && q.trim().length > 0;\n}","tryCatchPattern":"try {\n  await xiaohongshuAsk({ query });\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.message === 'query is required') {\n    console.error('Provide a non-empty question, e.g. opencli xiaohongshu ask \"how to X\"');\n  } else throw e;\n}","preventionTips":["Always quote the question argument in shell commands","Guard against unset shell variables expanding to empty strings (${Q:?unset})","Trim and validate the prompt in wrapper scripts before invoking","Fail fast in CI if the query input is blank"],"tags":["missing-argument","cli-option","xiaohongshu"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}