{"record":{"id":"779fcbf9b42edcb5","repo":"tonhowtf/omniget","slug":"source-do-arxiv-nao-parece-latex","errorCode":null,"errorMessage":"source do arXiv nao parece LaTeX","messagePattern":"source do arXiv nao parece LaTeX","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/arxiv.rs","lineNumber":374,"sourceCode":"    let mut out = Vec::new();\n    flate2::read::GzDecoder::new(b).read_to_end(&mut out)?;\n    Ok(out)\n}\n\n/// Aceita o tar.gz do `e-print`, um tar cru, um `.tex` gzipado ou o `.tex` solto.\npub fn extract_source(bytes: &[u8]) -> anyhow::Result<SourceBundle> {\n    if bytes.starts_with(b\"%PDF\") {\n        return Err(anyhow!(\"o source deste arXiv e um PDF, nao tem LaTeX\"));\n    }\n    let raw = if is_gzip(bytes) {\n        gunzip(bytes)?\n    } else {\n        bytes.to_vec()\n    };\n    if !is_tar(&raw) {\n        let text = String::from_utf8_lossy(&raw).to_string();\n        if !text.contains('\\\\') {\n            return Err(anyhow!(\"source do arXiv nao parece LaTeX\"));\n        }\n        return Ok(SourceBundle {\n            main: text,\n            files: vec![\"main.tex\".to_string()],\n        });\n    }\n\n    let mut texts: HashMap<String, String> = HashMap::new();\n    let mut names: Vec<String> = Vec::new();\n    let mut archive = tar::Archive::new(std::io::Cursor::new(&raw));\n    for entry in archive.entries()? {\n        let mut entry = entry?;\n        let path = entry.path()?.to_string_lossy().to_string();\n        let lower = path.to_lowercase();\n        if !(lower.ends_with(\".tex\") || lower.ends_with(\".bbl\") || lower.ends_with(\".ltx\")) {\n            continue;\n        }\n        let mut buf = Vec::new();","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/arxiv.rs#L356-L392","documentation":"extract_source first gunzips the payload, then checks whether it is a tar. If it is not a tar, it treats the bytes as a single loose .tex file — but only if the decoded text contains a backslash. If there is no backslash, the content cannot plausibly be LaTeX, so this error is thrown.","triggerScenarios":"The e-print payload is neither a tar nor LaTeX text: e.g. a PostScript file, a plain-text README, an HTML error page mis-served as the source, or binary garbage.","commonSituations":"Very old arXiv submissions stored as compressed PostScript; API/mirror returning an HTML block page for the source endpoint; corrupt or truncated download of the source bundle.","solutions":["Log the first bytes/content-type of the payload to identify what was actually downloaded.","Re-download the source — a truncated fetch can leave non-LaTeX garbage.","Check whether the paper uses PostScript (convert with ps2pdf or skip it).","Verify you're hitting arxiv.org directly and not an HTML error page behind a proxy."],"exampleFix":"// before\nif !text.contains('\\\\') {\n    return Err(anyhow!(\"source do arXiv nao parece LaTeX\"));\n}\n// after\nif !text.contains('\\\\') {\n    anyhow::bail!(\"source do arXiv nao parece LaTeX (inicio: {:?})\", &text.chars().take(120).collect::<String>());\n}","handlingStrategy":"validation","validationCode":"// apos baixar e gunzipar:\nlet text = String::from_utf8_lossy(&raw);\nif !is_tar(&raw) && !text.contains('\\\\') {\n    bail!(\"payload nao e tar nem LaTeX; content-type/inicio: {:?}\", &raw[..raw.len().min(64)]);\n}","typeGuard":null,"tryCatchPattern":"match extract_source(&bytes) {\n    Err(e) if e.to_string().contains(\"nao parece LaTeX\") => {\n        eprintln!(\"fonte em formato nao suportado (PostScript/HTML?); pulando id\");\n    }\n    other => other,\n}","preventionTips":["Inspect the first bytes/content-type of the source payload before parsing.","Verify downloads are complete (compare Content-Length) — truncation corrupts sniffing.","Avoid proxies/mirrors that may inject HTML error pages."],"tags":["arxiv","latex","content-sniffing","validation"],"backgroundTag":"incompatible-source-type","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"}