jackwener/OpenCLI · error
suggest failed
Error message
suggest failed
What it means
The nowcoder suggest command's in-page script POSTs the query to the search-suggestion endpoint with credentials included. If d.success is falsy it throws Error(d.msg || 'suggest failed'); 'suggest failed' is the fallback message when the API returns no msg. It indicates the suggestion API refused the request.
Source
Thrown at clis/nowcoder/suggest.js:24
access: 'read',
description: 'Search suggestions',
domain: 'www.nowcoder.com',
args: [
{ name: 'query', positional: true, required: true, help: 'Search keyword' },
],
columns: ['rank', 'suggestion', 'type'],
pipeline: [
{ navigate: 'https://www.nowcoder.com' },
{ evaluate: `(async () => {
const query = \${{ args.query | json }};
const r = await fetch('https://gw-c.nowcoder.com/api/sparta/search/suggest', {
method: 'POST',
credentials: 'include',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({query})
});
const d = await r.json();
if (!d.success) throw new Error(d.msg || 'suggest failed');
return (d.data?.records || []).map((item, i) => ({
rank: i + 1,
suggestion: item.name || '',
type: item.typeName || 'general',
}));
})()
` },
{ limit: '10' },
],
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Log in to nowcoder.com in the automated browser so credentials:'include' carries a session
- Simplify the query (remove unusual characters) and retry
- Retry later in case of rate limiting
- Capture the raw response and update the endpoint/body in clis/nowcoder/suggest.js if the API contract changed
Example fix
// before
if (!d.success) throw new Error(d.msg || 'suggest failed');
// after
if (!d.success) throw new Error('suggest failed: ' + (d.msg || 'code=' + d.code)); Defensive patterns
Strategy: retry
Validate before calling
const q = typeof query === 'string' ? query.trim() : '';
if (!q) throw new Error('suggest requires a non-empty query'); Type guard
function suggestOk(d){ return !!d && typeof d === 'object' && d.success === true && Array.isArray(d.data?.records); } Try / catch
try { await run(['nowcoder', 'suggest', '--query', q]); }
catch (e) {
if (String(e.message).includes('suggest failed')) { await sleep(2000); /* retry once, or check session */ }
else throw e;
} Prevention
- Keep the browser session authenticated so credentials:'include' works
- Keep queries simple; strip characters that may trip server validation
- Retry with backoff — suggestion endpoints are frequently rate limited
- Check r.ok before r.json() to distinguish HTTP from business failures
When it happens
Trigger: Running `nowcoder suggest` when the suggestion endpoint responds success:false without a msg — empty/odd query payloads, missing session cookie, endpoint renamed, or throttling.
Common situations: Unauthenticated browser session; Nowcoder changing the suggest endpoint or request body shape; special characters in the query tripping server validation; gateway incidents.
Related errors
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/89e991c6eb775559.
Report an issue: GitHub.