{"record":{"id":"06826a8dff87881d","repo":"datawhalechina/hello-agents","slug":"error-06826a","errorCode":null,"errorMessage":"猜测失败","messagePattern":"猜测失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"Co-creation-projects/afei-GuessWhoAmI/frontend/app.js","lineNumber":202,"sourceCode":"      alert('请输入猜测的人物姓名');\n      return;\n    }\n    if (!this.sessionId) return;\n\n    this.setControlsDisabled(true);\n\n    try {\n      const response = await fetch('http://localhost:8000/api/game/guess', {\n        method: 'POST',\n        headers: {'Content-Type': 'application/json'},\n        body: JSON.stringify({session_id: this.sessionId, guess: guess})\n      });\n\n      if (!response.ok) throw new Error(`HTTP error: ${response.status}`);\n\n      const result = await response.json();\n\n      if (!result.success) throw new Error(result.error || '猜测失败');\n\n      const data = result.data;\n      guessInput.value = '';\n\n      if (data.is_correct) {\n        this.addMessage(`🎉 恭喜！你猜对了！答案就是：${guess}`, 'agent');\n        this.endGame(true, data.figure_info, data.portrait_images || []);\n      } else {\n        this.addMessage(`❌ 猜错了！${data.message || '再想想看~'}`, 'agent');\n        this.remainingQuestions = data.remaining_questions !== undefined ?\n            data.remaining_questions :\n            this.remainingQuestions - 1;\n        this.updateStats();\n\n        if (data.is_game_over || this.remainingQuestions <= 0) {\n          this.endGame(false);\n        }\n      }","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/afei-GuessWhoAmI/frontend/app.js#L184-L220","documentation":"Application guard for the guess call: 2xx + JSON but result.success falsy; throws result.error or the '猜测失败' fallback. Note this is distinct from a wrong guess (is_correct:false inside success:true) — this means the guess request itself was rejected.","triggerScenarios":"Backend returns success:false for unknown session, game already over, or evaluation errors — with error omitted, giving the generic text. Follows the same envelope drift risks as the other game endpoints.","commonSituations":"Guessing after game over; backend refactor renaming success/error fields; evaluation exception swallowed into success:false.","solutions":["Log the full result and fix the backend to return a descriptive error for every success:false path","Guard the UI: disable guess input once is_game_over is seen","On session-invalid errors, auto-restart the game","Pin the response envelope in a shared type/schema"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if (!this.sessionId || this.gameOver) return;","typeGuard":"function isGuessResult(r) { return r && typeof r.success === 'boolean' && (!r.success || ('data' in r && typeof r.data.is_correct === 'boolean')); }","tryCatchPattern":"try { ... } catch (e) { alert(`猜测失败：${e.message}`); }","preventionTips":["Lock the guess input after game over","Envelope contract tests on the backend","Distinguish business rejection (success:false) from wrong guess (is_correct:false) in UI copy"],"tags":["api-envelope","guess","game"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}