{"record":{"id":"121372991b3bd171","repo":"jackwener/OpenCLI","slug":"label-returned-an-unexpected-response","errorCode":null,"errorMessage":"${label} returned an unexpected response","messagePattern":"(.+?) returned an unexpected response","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/jike/utils.js","lineNumber":85,"sourceCode":"      } catch (error) {\n        return { kind: 'json', status: response.status, detail: String(error?.message || error) };\n      }\n      return { kind: 'response', status: response.status, body };\n    } catch (error) {\n      return { kind: 'transport', detail: String(error?.message || error) };\n    }\n  })()`);\n  if (outcome?.kind === 'auth' || outcome?.status === 401 || outcome?.status === 403) {\n    throw new AuthRequiredError('web.okjike.com', outcome?.detail || `${label} returned HTTP ${outcome?.status}`);\n  }\n  if (outcome?.kind === 'transport') {\n    throw new CommandExecutionError(`${label} request failed: ${outcome.detail}`);\n  }\n  if (outcome?.kind === 'json') {\n    throw new CommandExecutionError(`${label} returned invalid JSON: ${outcome.detail}`);\n  }\n  if (outcome?.kind !== 'response' || !Number.isInteger(outcome.status)) {\n    throw new CommandExecutionError(`${label} returned an unexpected response`);\n  }\n  if (outcome.status < 200 || outcome.status >= 300) {\n    throw new CommandExecutionError(`${label} returned HTTP ${outcome.status}`);\n  }\n  return outcome.body;\n}\n\n/**\n * 注入浏览器 evaluate 的 JS 函数字符串。\n * 从 React fiber 树中向上最多走 10 层，找到含 id 字段的 props.data。\n */\nexport const getPostDataJs = `\nfunction getPostData(element) {\n  for (const key of Object.keys(element)) {\n    if (key.startsWith('__reactFiber$') || key.startsWith('__reactInternalInstance$')) {\n      let fiber = element[key];\n      for (let i = 0; i < 10 && fiber; i++) {\n        const props = fiber.memoizedProps || fiber.pendingProps;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/jike/utils.js#L67-L103","documentation":"postJikeApi validates the shape of the outcome returned by its internal fetch wrapper. If the outcome is not of kind 'response' or its status is not an integer, the contract between the wrapper and the parser is broken, so it throws CommandExecutionError('... returned an unexpected response'). This is a defensive invariant check for malformed or unclassified outcomes.","triggerScenarios":"The internal outcome object from the fetch wrapper is undefined, has an unknown kind value, or carries a non-integer/missing status — e.g. a wrapper bug, an unhandled response type, or the outcome object being corrupted/constructed incorrectly.","commonSituations":"A code change in the fetch wrapper introduced a new outcome kind not handled by postJikeApi; an unexpected runtime result (e.g. evaluate returning undefined); version drift between the wrapper and API helper.","solutions":["Inspect the raw outcome shape in the fetch wrapper (clis/jike/utils.js) to see which kind it produced","Add a handler for the unhandled kind in postJikeApi, or fix the wrapper to always classify outcomes","Update to the latest CLI version in case this is a known wrapper bug","Log the full outcome object (JSON.stringify) before this branch to diagnose","If triggered by a patched/hooked fetch environment, test in a clean environment"],"exampleFix":"// before (wrapper returns an unclassified kind)\nreturn { kind: 'redirect', location: res.headers.get('location') };\n// after\nclassify: follow the redirect inside the wrapper and return { kind: 'response', status, body };","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isWellFormedOutcome(outcome) {\n  return outcome != null && typeof outcome === 'object' &&\n    (outcome.kind === 'response' || outcome.kind === 'transport' || outcome.kind === 'json' || outcome.kind === 'auth') &&\n    (outcome.kind !== 'response' || Number.isInteger(outcome.status));\n}","tryCatchPattern":"try {\n  const body = await body('postJikeApi', path, payload);\n} catch (err) {\n  if (err instanceof CommandExecutionError && /unexpected response/.test(err.message)) {\n    console.error('postJikeApi contract violated — inspect outcome from fetch wrapper', err);\n  }\n  throw err;\n}","preventionTips":["Keep the fetch wrapper and postJikeApi outcome contract in sync","Update the CLI as a whole (avoid mixing versions of utils.js)","Unit-test the wrapper against all outcome kinds","Never manually construct outcome objects with unknown kinds"],"tags":["invariant","contract-violation","jike","command-execution-error"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}