{"record":{"id":"dbf5ca12d47585f5","repo":"jackwener/OpenCLI","slug":"nowcoder-search-requires-a-non-empty-query","errorCode":null,"errorMessage":"nowcoder search requires a non-empty query","messagePattern":"nowcoder search requires a non-empty query","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/nowcoder/search.js","lineNumber":26,"sourceCode":"\ncli({\n    site: 'nowcoder',\n    name: 'search',\n    access: 'read',\n    description: 'Search content and moment posts',\n    domain: 'www.nowcoder.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    navigateBefore: false,\n    args: [\n        { name: 'query', positional: true, required: true, help: 'Search keyword' },\n        { name: 'type', type: 'str', default: 'post', help: 'Post search scope (post/all)' },\n        { name: 'limit', type: 'int', default: 10, help: 'Number of posts (1-50)' },\n    ],\n    columns: ['rank', 'post_type', 'id', 'uuid', 'entity_id', 'url', 'title', 'author', 'author_id', 'author_url', 'school', 'content', 'likes', 'comments', 'views', 'time'],\n    func: async (page, args) => {\n        const query = typeof args.query === 'string' ? args.query.trim() : '';\n        if (!query) throw new ArgumentError('nowcoder search requires a non-empty query');\n        const type = args.type ?? 'post';\n        if (type !== 'all' && type !== 'post') {\n            throw new ArgumentError('nowcoder search --type must be all or post');\n        }\n        const limit = requirePositiveInt(args.limit ?? 10, 'limit', 50);\n        const data = await fetchNowcoderData(\n            page,\n            'https://gw-c.nowcoder.com/api/sparta/pc/search',\n            { method: 'POST', body: { query, type, page: 1, pageSize: limit }, timeoutMs: 15_000 },\n            'Nowcoder search request',\n        );\n        return projectNowcoderFeed(data.records, limit, 'search', type === 'all');\n    },\n});\n","sourceCodeStart":8,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/search.js#L8-L41","documentation":"The nowcoder search command validates its arguments before calling the API. If args.query is missing, not a string, or only whitespace, it throws ArgumentError('nowcoder search requires a non-empty query'). This is a fail-fast input validation, not a network error.","triggerScenarios":"Invoking `nowcoder search` without --query, with --query \"\" or --query \"   \", or passing a non-string value for query.","commonSituations":"Shell quoting mistakes dropping the argument; scripting the CLI and forgetting the query field; an upstream pipeline passing an empty variable.","solutions":["Pass a non-empty --query value, e.g. nowcoder search --query \"golang\"","Trim and check the query in the calling script before invoking the CLI","If scripted, abort early when the query variable is empty"],"exampleFix":"// before\nawait run(['nowcoder', 'search', '--query', q]);\n// after\nif (!q || !q.trim()) throw new Error('search query required');\nawait run(['nowcoder', 'search', '--query', q.trim()]);","handlingStrategy":"validation","validationCode":"const q = typeof query === 'string' ? query.trim() : '';\nif (!q) throw new Error('nowcoder search --query must be a non-empty string');","typeGuard":"function isNonEmptyString(v){ return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try { await run(['nowcoder', 'search', '--query', q]); }\ncatch (e) {\n  if (e instanceof ArgumentError && /non-empty query/.test(e.message)) {\n    console.error('Usage: nowcoder search --query <text> [--type post|all] [--limit N]');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Always pass --quote-quoted query values in shell scripts","Trim and assert query non-empty in upstream pipelines before invoking","Add CLI argument checks in wrapper scripts before spawning the command","Remember type defaults to post; only all/post are valid"],"tags":["argument-validation","cli","nowcoder"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}