{"record":{"id":"68ce5a03257f322e","repo":"ATH-MaaS/Pixelle-Video","slug":"str-e","errorCode":null,"errorMessage":"str(e)","messagePattern":"str\\(e\\)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/content.py","lineNumber":75,"sourceCode":"    try:\n        logger.info(f\"Generating {request.n_scenes} narrations from text\")\n        \n        # Call narration generator utility function\n        narrations = await generate_narrations_from_topic(\n            llm_service=pixelle_video.llm,\n            topic=request.text,\n            n_scenes=request.n_scenes,\n            min_words=request.min_words,\n            max_words=request.max_words\n        )\n        \n        return NarrationGenerateResponse(\n            narrations=narrations\n        )\n        \n    except Exception as e:\n        logger.error(f\"Narration generation error: {e}\")\n        raise HTTPException(status_code=500, detail=str(e))\n\n\n@router.post(\"/image-prompt\", response_model=ImagePromptGenerateResponse)\nasync def generate_image_prompt(\n    request: ImagePromptGenerateRequest,\n    pixelle_video: PixelleVideoDep\n):\n    \"\"\"\n    Generate image prompts from narrations\n    \n    Uses LLM to create detailed image generation prompts.\n    \n    - **narrations**: List of narration texts\n    - **min_words**: Minimum words per prompt\n    - **max_words**: Maximum words per prompt\n    \n    Returns list of image prompts.\n    \"\"\"","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/api/routers/content.py#L57-L93","documentation":"The POST /narration handler catches any exception from narration generation and re-raises it as an HTTP 500 with the raw exception string as the detail. This is a catch-all: any failure inside the narration pipeline (LLM call, model config, serialization) surfaces as this opaque 500. The message is whatever str(e) produced, so it can be almost anything.","triggerScenarios":"POST to the narration endpoint where the underlying narration generation service raises any non-HTTPException error — e.g. missing/invalid AI provider API key, network failure to the LLM, malformed model output that fails response parsing, or an unexpected None/type error in the generation code.","commonSituations":"Missing or expired OPENAI/provider API key in the environment; the narration model returns JSON that fails validation; transient provider timeouts; a bug introduced in the generation service after a dependency upgrade.","solutions":["Read the server log line 'Narration generation error: ...' — the detail is duplicated there with more context.","Verify the AI provider API key/env vars are set and valid for narration generation.","Call the narration generation path directly (script/tests) to reproduce the underlying exception outside the HTTP layer.","Retry once if the log indicates a transient network/timeout error from the provider.","Replace str(e) detail with a generic message and log the full traceback server-side to avoid leaking internals."],"exampleFix":"// before\nexcept Exception as e:\n    logger.error(f\"Narration generation error: {e}\")\n    raise HTTPException(status_code=500, detail=str(e))\n// after\nexcept Exception as e:\n    logger.exception(\"Narration generation error\")\n    raise HTTPException(status_code=500, detail=\"Narration generation failed\")","handlingStrategy":"try-catch","validationCode":"if (!process.env.AI_API_KEY) throw new Error('AI provider API key not configured before calling narration endpoint');\nconst res = await fetch('/api/content/narration', { method: 'POST', body: JSON.stringify(req) });\nif (res.status === 500) console.error('Narration generation failed; check server logs for root cause');","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch('/api/content/narration', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(request) });\n  if (!res.ok) {\n    const detail = (await res.json()).detail;\n    throw new Error(`Narration generation failed (500): ${detail}`);\n  }\n  return await res.json();\n} catch (err) {\n  logger.error('Narration request failed', err);\n  throw err;\n}","preventionTips":["Validate AI provider credentials at service startup, not per-request.","Add health/readiness checks for the upstream LLM provider.","Monitor server logs for 'Narration generation error' to catch root causes early.","Retry transient provider failures with exponential backoff on the client."],"tags":["http-500","api","llm","generic-error"],"backgroundTag":"internal-server-error-500","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}