jackwener/OpenCLI · error · ArgumentError
nowcoder search --type must be all or post
Error message
nowcoder search --type must be all or post
What it means
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.
Source
Thrown at clis/nowcoder/search.js:29
name: 'search',
access: 'read',
description: 'Search content and moment posts',
domain: 'www.nowcoder.com',
strategy: Strategy.COOKIE,
browser: true,
navigateBefore: false,
args: [
{ name: 'query', positional: true, required: true, help: 'Search keyword' },
{ name: 'type', type: 'str', default: 'post', help: 'Post search scope (post/all)' },
{ name: 'limit', type: 'int', default: 10, help: 'Number of posts (1-50)' },
],
columns: ['rank', 'post_type', 'id', 'uuid', 'entity_id', 'url', 'title', 'author', 'author_id', 'author_url', 'school', 'content', 'likes', 'comments', 'views', 'time'],
func: async (page, args) => {
const query = typeof args.query === 'string' ? args.query.trim() : '';
if (!query) throw new ArgumentError('nowcoder search requires a non-empty query');
const type = args.type ?? 'post';
if (type !== 'all' && type !== 'post') {
throw new ArgumentError('nowcoder search --type must be all or post');
}
const limit = requirePositiveInt(args.limit ?? 10, 'limit', 50);
const data = await fetchNowcoderData(
page,
'https://gw-c.nowcoder.com/api/sparta/pc/search',
{ method: 'POST', body: { query, type, page: 1, pageSize: limit }, timeoutMs: 15_000 },
'Nowcoder search request',
);
return projectNowcoderFeed(data.records, limit, 'search', type === 'all');
},
});
View on GitHub (pinned to 49907e53dc)
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
Example fix
// before nowcoder search --query golang --type questions // after nowcoder search --query golang --type all
Defensive patterns
Strategy: validation
Validate before calling
const allowed = ['post','all'];
if (!allowed.includes(type)) throw new Error(`--type must be one of ${allowed.join(', ')}`); Type guard
function isSearchType(v){ return v === 'post' || v === 'all'; } Try / catch
try { await run(['nowcoder', 'search', '--query', q, '--type', type]); }
catch (e) {
if (e instanceof ArgumentError && /--type must be all or post/.test(e.message)) {
type = 'post'; // fall back to default scope and retry
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- huodongxing eventType must be 1 (offline) or 2 (online)
- juejin category "${value}" is not recognised
- weread-official: type must be one of: ${Object.keys(TYPE_ALI
- weread-official: scope must be one of: ${Object.keys(SEARCH_
- weread-official: ${label} must be one of: ${choices.join(',
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/fc3b063ab694c914.
Report an issue: GitHub.