datawhalechina/hello-agents · error
启动失败
Error message
启动失败
What it means
Application-level error guard in startNewGame(): the backend returned 2xx and the body parsed as JSON, but result.success is falsy, so it throws result.error or the literal '启动失败'. The backend uses a {success, error, data} envelope; this branch means the game session could not be created for a business reason (no figures loaded, agent init failure).
Source
Thrown at Co-creation-projects/afei-GuessWhoAmI/frontend/app.js:55
}
// Start new game
async startNewGame() {
try {
this.setStartBtnLoading(true);
this.showLoadingOverlay();
const response = await fetch('http://localhost:8000/api/game/start', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({})
});
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;
this.sessionId = data.session_id;
this.remainingQuestions = data.max_questions || 20;
this.remainingHints = data.max_hints || 3;
// Switch to game screen
document.getElementById('intro-section').classList.add('hidden');
document.getElementById('game-section').classList.remove('hidden');
document.getElementById('result-modal').classList.add('hidden');
// Enable controls
document.getElementById('user-input').disabled = false;
document.getElementById('send-btn').disabled = false;
document.getElementById('get-hint').disabled = false;
document.getElementById('guess-btn').disabled = false;
document.getElementById('guess-input').disabled = false;
View on GitHub (pinned to 606a07d341)
Solutions
- Log the full result object to see what the backend actually returned; fix the backend condition that sets success:false
- Check backend startup logs for dataset/API-key initialization failures
- Verify the envelope contract ({success, error, data}) still matches on both sides after backend changes
- Return a specific error string from the backend instead of relying on the frontend fallback
Defensive patterns
Strategy: type-guard
Type guard
function isGameStartResult(r) { return r && typeof r.success === 'boolean' && r.data && 'session_id' in r.data; } Try / catch
try { const r = await startGame(); if (!r.success) throw new Error(r.error || '启动失败'); } catch (e) { alert(e.message); } Prevention
- Backend must always populate error when success is false
- Log the raw envelope on failure during development
- Pin the envelope shape with a shared type or schema
When it happens
Trigger: POST /api/game/start succeeding HTTP-wise but with success:false — e.g. figure pool empty because the data file failed to load, LLM client initialization failed, or max session limits reached. The literal '启动失败' appears only when the backend also omitted error.
Common situations: Backend starts but its figure dataset/config is missing; API key for the LLM not configured so session creation aborts; envelope field renamed (ok/status instead of success) after a backend refactor so success is always undefined.
Related errors
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/f9a4a0b8aa68a497.
Report an issue: GitHub.