{"record":{"id":"89e991c6eb775559","repo":"jackwener/OpenCLI","slug":"suggest-failed","errorCode":null,"errorMessage":"suggest failed","messagePattern":"suggest failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/nowcoder/suggest.js","lineNumber":24,"sourceCode":"    access: 'read',\n    description: 'Search suggestions',\n    domain: 'www.nowcoder.com',\n    args: [\n        { name: 'query', positional: true, required: true, help: 'Search keyword' },\n    ],\n    columns: ['rank', 'suggestion', 'type'],\n    pipeline: [\n        { navigate: 'https://www.nowcoder.com' },\n        { evaluate: `(async () => {\n  const query = \\${{ args.query | json }};\n  const r = await fetch('https://gw-c.nowcoder.com/api/sparta/search/suggest', {\n    method: 'POST',\n    credentials: 'include',\n    headers: {'Content-Type': 'application/json'},\n    body: JSON.stringify({query})\n  });\n  const d = await r.json();\n  if (!d.success) throw new Error(d.msg || 'suggest failed');\n  return (d.data?.records || []).map((item, i) => ({\n    rank: i + 1,\n    suggestion: item.name || '',\n    type: item.typeName || 'general',\n  }));\n})()\n` },\n        { limit: '10' },\n    ],\n});\n","sourceCodeStart":6,"sourceCodeEnd":35,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/suggest.js#L6-L35","documentation":"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.","triggerScenarios":"Running `nowcoder suggest` when the suggestion endpoint responds success:false without a msg — empty/odd query payloads, missing session cookie, endpoint renamed, or throttling.","commonSituations":"Unauthenticated browser session; Nowcoder changing the suggest endpoint or request body shape; special characters in the query tripping server validation; gateway incidents.","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"],"exampleFix":"// before\nif (!d.success) throw new Error(d.msg || 'suggest failed');\n// after\nif (!d.success) throw new Error('suggest failed: ' + (d.msg || 'code=' + d.code));","handlingStrategy":"retry","validationCode":"const q = typeof query === 'string' ? query.trim() : '';\nif (!q) throw new Error('suggest requires a non-empty query');","typeGuard":"function suggestOk(d){ return !!d && typeof d === 'object' && d.success === true && Array.isArray(d.data?.records); }","tryCatchPattern":"try { await run(['nowcoder', 'suggest', '--query', q]); }\ncatch (e) {\n  if (String(e.message).includes('suggest failed')) { await sleep(2000); /* retry once, or check session */ }\n  else throw e;\n}","preventionTips":["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"],"tags":["nowcoder","in-page-script","api-error"],"backgroundTag":"api-business-error-code","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}