{"record":{"id":"5356386a77e22892","repo":"lfnovo/open-notebook","slug":"failed-to-delete-episode","errorCode":null,"errorMessage":"Failed to delete episode","messagePattern":"Failed to delete episode","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/podcasts.py","lineNumber":430,"sourceCode":"        # Get the episode first to check if it exists and get the audio file path\n        episode = await PodcastService.get_episode(episode_id)\n\n        # Delete the physical audio file if it exists\n        _delete_episode_audio(episode, episode_id)\n\n        # Delete the episode from the database\n        await episode.delete()\n\n        logger.info(f\"Deleted podcast episode: {episode_id}\")\n        return {\"message\": \"Episode deleted successfully\", \"episode_id\": episode_id}\n\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error deleting podcast episode: {str(e)}\")\n        raise HTTPException(\n            status_code=500, detail=\"Failed to delete episode\"\n        )\n","sourceCodeStart":412,"sourceCodeEnd":433,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/podcasts.py#L412-L433","documentation":"Generic 500 from the delete-podcast-episode endpoint when an unexpected exception occurs while deleting an episode. The true cause is only in the server log ('Error deleting podcast episode: ...').","triggerScenarios":"DELETE /api/podcasts/episodes/{episode_id} when the delete touches missing records, fails a DB transaction, or the episode has orphaned related rows that break deletion logic.","commonSituations":"Deleting an already-deleted episode concurrently, SurrealDB down or schema drift after migration, foreign references (notes, jobs) pointing at the episode.","solutions":["Check server logs for the underlying exception string","Verify the episode_id exists via GET before deleting","Ensure SurrealDB is running and migrations completed on API startup","Remove dependent records (notes, jobs) or rely on cascade if implemented"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const res = await fetch(`/api/podcasts/episodes/${id}`);\nif (res.status === 404) { /* nothing to delete */ }","typeGuard":null,"tryCatchPattern":"try {\n  await api.delete(`/podcasts/episodes/${id}`);\n} catch (e) {\n  if (e.status === 500) refreshListAndCheckServerLogs();\n}","preventionTips":["Guard against double-deletes from stale UI state","Confirm DB connectivity before bulk deletes","Handle 404 as success (already deleted)"],"tags":["podcast","delete","http-500","database"],"backgroundTag":"delete-operation-failed","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}