datawhalechina/hello-agents · warning

猜测失败

Error message

猜测失败

What it means

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.

Source

Thrown at Co-creation-projects/afei-GuessWhoAmI/frontend/app.js:202

      alert('请输入猜测的人物姓名');
      return;
    }
    if (!this.sessionId) return;

    this.setControlsDisabled(true);

    try {
      const response = await fetch('http://localhost:8000/api/game/guess', {
        method: 'POST',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify({session_id: this.sessionId, guess: guess})
      });

      if (!response.ok) throw new Error(`HTTP error: ${response.status}`);

      const result = await response.json();

      if (!result.success) throw new Error(result.error || '猜测失败');

      const data = result.data;
      guessInput.value = '';

      if (data.is_correct) {
        this.addMessage(`🎉 恭喜!你猜对了!答案就是:${guess}`, 'agent');
        this.endGame(true, data.figure_info, data.portrait_images || []);
      } else {
        this.addMessage(`❌ 猜错了!${data.message || '再想想看~'}`, 'agent');
        this.remainingQuestions = data.remaining_questions !== undefined ?
            data.remaining_questions :
            this.remainingQuestions - 1;
        this.updateStats();

        if (data.is_game_over || this.remainingQuestions <= 0) {
          this.endGame(false);
        }
      }

View on GitHub (pinned to 606a07d341)

Solutions

  1. Log the full result and fix the backend to return a descriptive error for every success:false path
  2. Guard the UI: disable guess input once is_game_over is seen
  3. On session-invalid errors, auto-restart the game
  4. Pin the response envelope in a shared type/schema
Defensive patterns

Strategy: type-guard

Validate before calling

if (!this.sessionId || this.gameOver) return;

Type guard

function isGuessResult(r) { return r && typeof r.success === 'boolean' && (!r.success || ('data' in r && typeof r.data.is_correct === 'boolean')); }

Try / catch

try { ... } catch (e) { alert(`猜测失败:${e.message}`); }

Prevention

When it happens

Trigger: 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.

Common situations: Guessing after game over; backend refactor renaming success/error fields; evaluation exception swallowed into success:false.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/06826a8dff87881d. Report an issue: GitHub.