{"record":{"id":"33ae1058e37dc87f","repo":"tonhowtf/omniget","slug":"o-json-do-yt-dlp-n-o-foi-lido","errorCode":null,"errorMessage":"o JSON do yt-dlp não foi lido: {}","messagePattern":"o JSON do yt-dlp não foi lido: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/tiktok/mod.rs","lineNumber":759,"sourceCode":"    cmd.args(args)\n        .stdin(std::process::Stdio::null())\n        .stdout(std::process::Stdio::piped())\n        .stderr(std::process::Stdio::piped());\n    let out = cmd\n        .output()\n        .await\n        .map_err(|e| anyhow!(\"não foi possível iniciar o yt-dlp: {}\", e))?;\n    let text = String::from_utf8_lossy(&out.stdout);\n    let line = text\n        .lines()\n        .map(|l| l.trim())\n        .find(|l| l.starts_with('{'))\n        .unwrap_or(\"\");\n    if line.is_empty() {\n        let tail = String::from_utf8_lossy(&out.stderr).to_string();\n        return Err(anyhow!(\"{}\", short_reason(&tail)));\n    }\n    serde_json::from_str(line).map_err(|e| anyhow!(\"o JSON do yt-dlp não foi lido: {}\", e))\n}\n\n// ───────────────────────── formatação ─────────────────────────\n\npub fn fmt_utc(ts: i64) -> String {\n    chrono::DateTime::from_timestamp(ts, 0)\n        .map(|d| d.format(\"%Y-%m-%d %H:%M UTC\").to_string())\n        .unwrap_or_default()\n}\n\n/// Escapa um campo de CSV do jeito que a planilha espera.\npub fn csv_escape(s: &str) -> String {\n    if s.contains([',', '\"', '\\n', '\\r']) {\n        format!(\"\\\"{}\\\"\", s.replace('\"', \"\\\"\\\"\"))\n    } else {\n        s.to_string()\n    }\n}","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/tiktok/mod.rs#L741-L777","documentation":"`ytdlp_json` found a stdout line starting with '{' but `serde_json::from_str` failed to parse it, producing \"o JSON do yt-dlp não foi lido\". This means yt-dlp emitted something JSON-like that is not the expected single-line JSON object — typically truncated output or an unexpected shape.","triggerScenarios":"yt-dlp's stdout line starting with '{' is truncated (pipe closed early, output limit) or is not valid JSON (progress lines interleaved, multi-line pretty JSON picked mid-stream); a yt-dlp version changed its `--dump-json`/`-j` output format.","commonSituations":"Running a very old or patched yt-dlp whose JSON schema differs; process killed mid-write; wrapping the binary with a script that prints banners; encoding issues corrupting the line.","solutions":["Update yt-dlp to the latest stable version so `-j` output matches the parser's expectations.","Run yt-dlp manually with the same args and inspect the raw JSON line for truncation or noise.","Ensure the child process is fully drained (stdout read to EOF) before parsing.","If parsing must be lenient, fall back to locating the full JSON object instead of the first '{'-prefixed line."],"exampleFix":"// before\nserde_json::from_str(line).map_err(|e| anyhow!(\"o JSON do yt-dlp não foi lido: {}\", e))?\n// after\nlet v: serde_json::Value = serde_json::from_str(line)\n    .map_err(|e| anyhow!(\"o JSON do yt-dlp não foi lido: {}; line={}\", e, &line[..line.len().min(200)]))?;","handlingStrategy":"try-catch","validationCode":"// Drain the full stdout and confirm the first non-empty line parses before trusting it\nlet line = text.lines().map(str::trim).find(|l| l.starts_with('{')).unwrap_or(\"\");\nserde_json::from_str::<serde_json::Value>(line).is_ok()","typeGuard":null,"tryCatchPattern":"match serde_json::from_str::<serde_json::Value>(line) {\n    Ok(v) => Ok(v),\n    Err(e) => Err(anyhow!(\"JSON inválido do yt-dlp ({e}); saída: {}\", truncate(line, 200))),\n}","preventionTips":["Use a pinned, recent yt-dlp version so `-j` output is a single valid JSON line.","Log the offending line (truncated) alongside the parse error to diagnose truncation.","Avoid other processes/scripts writing into yt-dlp's stdout."],"tags":["json","parsing","ytdlp"],"backgroundTag":"json-decode-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}