{"record":{"id":"fc3b063ab694c914","repo":"jackwener/OpenCLI","slug":"nowcoder-search-type-must-be-all-or-post","errorCode":null,"errorMessage":"nowcoder search --type must be all or post","messagePattern":"nowcoder search --type must be all or post","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/nowcoder/search.js","lineNumber":29,"sourceCode":"    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":11,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/search.js#L11-L41","documentation":"nowcoder search accepts --type of only 'post' or 'all' (defaulting to 'post'). Any other value throws ArgumentError('nowcoder search --type must be all or post'). It prevents sending an unsupported scope to the /api/sparta/pc/search endpoint.","triggerScenarios":"Invoking `nowcoder search --type` with a value other than all/post, e.g. --type user, --type question, --type jobs, or a misspelled value like --type posts (plural).","commonSituations":"Guessing the valid enum values; copying a --type flag from another CLI; typos such as 'Posts' (case-sensitive check); scripting with a variable that holds an out-of-range scope.","solutions":["Use --type post (default) or --type all only","Check spelling and case — the comparison is exact","If other scopes are needed, verify the Nowcoder search API accepts them and update the validation in clis/nowcoder/search.js"],"exampleFix":"// before\nnowcoder search --query golang --type questions\n// after\nnowcoder search --query golang --type all","handlingStrategy":"validation","validationCode":"const allowed = ['post','all'];\nif (!allowed.includes(type)) throw new Error(`--type must be one of ${allowed.join(', ')}`);","typeGuard":"function isSearchType(v){ return v === 'post' || v === 'all'; }","tryCatchPattern":"try { await run(['nowcoder', 'search', '--query', q, '--type', type]); }\ncatch (e) {\n  if (e instanceof ArgumentError && /--type must be all or post/.test(e.message)) {\n    type = 'post'; // fall back to default scope and retry\n  } else throw e;\n}","preventionTips":["Only use --type post or --type all; watch for plural/typo variants","Note the check is case-sensitive — 'Post' is rejected","Whitelist the type value in wrapper scripts","Consult clis/nowcoder/search.js arg definitions for the canonical enum"],"tags":["argument-validation","cli","enum"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}