{"record":{"id":"dab6c602b8aa87ab","repo":"tonhowtf/omniget","slug":"tg-diag-list-media","errorCode":null,"errorMessage":"[TG] diag_list_media:","messagePattern":"\\[TG\\] diag_list_media:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lib/study-components/TelegramBrowser.svelte","lineNumber":1460,"sourceCode":"    void preloadCachedThumbs(chat.id);\n    await loadMedia(true);\n    if (mediaItems.length === 0 && !mediaError && mediaFilter !== \"all\") {\n      console.warn(\n        `[TG] selectChat: 0 items com filter=${mediaFilter}, tentando filter=all`,\n      );\n      mediaFilter = \"all\";\n      await loadMedia(true);\n    }\n    if (mediaItems.length === 0 && !mediaError) {\n      console.warn(\n        `[TG] selectChat: chat=\"${chat.title}\" tipo=${chat.chat_type} retornou 0 medias mesmo com filter=all — rodando diag`,\n      );\n      try {\n        const diag = await telegramDiagListMedia({\n          chatId: chat.id,\n          chatType: chat.chat_type,\n        });\n        console.warn(\"[TG] diag_list_media:\", diag);\n        if (diag.get_history_error) {\n          mediaError = `Telegram negou acesso: ${diag.get_history_error}`;\n        } else if (diag.search_errors.length > 0) {\n          mediaError = `Telegram retornou erros nos filtros: ${diag.search_errors.join(\"; \")}. Possivelmente este channel é protegido (saving disabled) ou access_hash expirou. Tente sair e entrar novamente no chat pelo Telegram oficial.`;\n        } else if (diag.get_history_count === 0 && diag.search_photo_count === 0 && diag.search_video_count === 0 && diag.search_document_count === 0) {\n          mediaError = \"Channel parece não ter mídia acessível via API (broadcast protegido ou content sem media). Verifique no Telegram oficial se vê os videos.\";\n        } else if (diag.get_history_with_media === 0) {\n          mediaError = `Channel tem ${diag.get_history_count} mensagens mas nenhuma com mídia detectável. Verifique se as mensagens têm videos anexados (não apenas links).`;\n        }\n      } catch (e) {\n        console.warn(\"[TG] diag_list_media failed:\", e);\n      }\n    }\n    void loadPlaybackForChat(chat.id);\n  }\n\n  async function preloadCachedThumbs(chatId: number) {\n    try {","sourceCodeStart":1442,"sourceCodeEnd":1478,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src/lib/study-components/TelegramBrowser.svelte#L1442-L1478","documentation":"Diagnostic output from the Telegram media browser: telegramDiagListMedia ran but the Telegram backend reported problems (get_history_error, per-filter search_errors, or all counts zero). The component logs the raw diag object and converts it into a user-facing mediaError string explaining the likely cause.","triggerScenarios":"Calling telegramDiagListMedia({ chatId, chatType }) returns diag with get_history_error set, non-empty search_errors, or get_history_count === 0 and all media search counts === 0.","commonSituations":"Channels with restricted/saved-content (protected broadcast), expired access_hash after the chat was re-joined, Telegram API permission denial for the account/session, or channels genuinely without media.","solutions":["Read diag.get_history_error / diag.search_errors for the concrete Telegram API message","If access_hash expired: leave and rejoin the chat in the official Telegram client, then retry","If the channel is protected (saving disabled), media cannot be fetched — inform the user","Re-authenticate the Telegram session if permission was denied"],"exampleFix":"// before\nif (diag.get_history_error) {\n  mediaError = `Telegram negou acesso: ${diag.get_history_error}`;\n}\n// after\nif (diag.get_history_error) {\n  mediaError = `Telegram negou acesso: ${diag.get_history_error}`;\n  console.warn(\"[TG] diag_list_media raw:\", JSON.stringify(diag));\n}","handlingStrategy":"type-guard","validationCode":"const diag = await telegramDiagListMedia({ chatId: chat.id, chatType: chat.chat_type });\nif (!diag || (diag.get_history_count === 0 && diag.search_photo_count === 0 && diag.search_video_count === 0 && diag.search_document_count === 0 && !diag.get_history_error && diag.search_errors.length === 0)) return;","typeGuard":"function hasMediaAccess(diag: TgDiag): boolean {\n  return !diag.get_history_error && diag.search_errors.length === 0;\n}","tryCatchPattern":"try {\n  const diag = await telegramDiagListMedia({ chatId, chatType });\n  if (diag.get_history_error) mediaError = `Telegram negou acesso: ${diag.get_history_error}`;\n} catch (e) {\n  mediaError = \"Falha ao consultar mídia do chat\";\n  console.warn(\"[TG] diag_list_media threw:\", e);\n}","preventionTips":["Re-join chats in official Telegram when access_hash errors appear","Detect protected channels early and skip fetching","Keep the Telegram session authenticated and refreshed","Surface diag fields in UI instead of only console.warn"],"tags":["telegram","api","diagnostics"],"backgroundTag":"api-error-response","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}