{"record":{"id":"32805d47007f5fd8","repo":"tonhowtf/omniget","slug":"no-valid-cookies-found-in-file-expected-netscape-format","errorCode":null,"errorMessage":"No valid cookies found in file (expected Netscape format)","messagePattern":"No valid cookies found in file \\(expected Netscape format\\)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-cli/src/cookies.rs","lineNumber":92,"sourceCode":"    let content = std::fs::read_to_string(src_path)\n        .with_context(|| format!(\"Failed to read {}\", src_path.display()))?;\n\n    let cookies_dir = app_data_dir()\n        .ok_or_else(|| anyhow::anyhow!(\"Cannot determine app data directory\"))?\n        .join(COOKIES_DIR);\n\n    std::fs::create_dir_all(&cookies_dir)?;\n\n    let dest_file = if let Some(n) = name {\n        cookies_dir.join(format!(\"cookies_{}.txt\", n))\n    } else {\n        cookies_dir.join(DEFAULT_COOKIE_FILE)\n    };\n\n    // Parse to validate and count\n    let parsed = parse_netscape_cookies(&content);\n    if parsed.is_empty() {\n        anyhow::bail!(\"No valid cookies found in file (expected Netscape format)\");\n    }\n\n    // Copy the raw file (preserving original format for yt-dlp consumption)\n    // Normalize line endings but otherwise keep as-is\n    let normalized = content.replace(\"\\r\\n\", \"\\n\").replace('\\r', \"\\n\");\n    std::fs::write(&dest_file, normalized)\n        .with_context(|| format!(\"Failed to write {}\", dest_file.display()))?;\n\n    Ok(parsed.iter().map(|(_, s)| s.split(';').count()).sum())\n}\n\n/// List showing what the cookie file would look like when consumed\npub fn preview_import(src_path: &PathBuf) -> Result<Vec<(String, usize)>> {\n    let content = std::fs::read_to_string(src_path)\n        .with_context(|| format!(\"Failed to read {}\", src_path.display()))?;\n\n    let parsed = parse_netscape_cookies(&content);\n    Ok(parsed","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-cli/src/cookies.rs#L74-L110","documentation":"import_cookies_file validates a user-supplied cookie file by running it through parse_netscape_cookies before installing it into the cookies directory. The parser only accepts Netscape cookie-file lines with at least 7 tab-separated fields (domain, flag, path, secure, expiration, name, value) and non-empty name/value. If nothing in the file parses, import_cookies_file aborts with this error instead of copying a cookie file that yt-dlp would later reject or silently ignore.","triggerScenarios":"Calling import_cookies_file with a file whose contents yield zero parsed cookies: (1) a JSON cookie export (e.g. from browser extensions) rather than Netscape format; (2) a Netscape file where fields are separated by spaces instead of tabs (fields.len() < 7); (3) a file containing only comments (# lines), blank lines, or an HTTP Set-Cookie header dump; (4) an empty or binary (e.g. SQLite) file passed by mistake.","commonSituations":"Users export cookies from a browser extension in JSON format and pass that file; users hand-copy cookie text with spaces instead of tabs; users pass an HTML login page saved to disk or a curl cookie jar in a different dialect; the file was created empty because the export failed upstream.","solutions":["Export the cookies in Netscape format (e.g. a browser 'Get cookies.txt' extension, or `yt-dlp --cookies-from-browser <browser>` style export) and re-run import_cookies_file with that file.","Verify the file's lines have 7 tab-separated fields: domain\\tflag\\tpath\\tsecure\\texpiration\\tname\\tvalue; re-export or convert with a JSON-to-Netscape converter if separators are spaces or it is JSON.","Check the file is non-empty and contains actual cookie data (no leading #HttpOnly_ comments-only file, no truncated export) before importing.","If the file is fine but spaces-separated, convert separators to tabs (sed/awk) and retry."],"exampleFix":"// before: importing a JSON export\nlet raw = std::fs::read_to_string(\"cookies.json\").unwrap();\nimport_cookies_file(\"cookies.json\").unwrap(); // bail: No valid cookies found\n// after: convert JSON to Netscape format first (name\\tvalue lines with 7 tab fields), then import\n// cookies.txt:\n// .example.com\tTRUE\t/\tTRUE\t1735689600\tSESSION\tabc123\nimport_cookies_file(\"cookies.txt\").unwrap();","handlingStrategy":"validation","validationCode":"fn is_netscape_cookie_file(path: &str) -> bool {\n    let content = std::fs::read_to_string(path).unwrap_or_default();\n    content.lines().any(|l| {\n        let l = l.trim();\n        !l.is_empty() && !l.starts_with('#') && l.split('\\t').count() >= 7\n    })\n}\nif !is_netscape_cookie_file(\"cookies.txt\") {\n    eprintln!(\"not a Netscape cookies.txt file\");\n}","typeGuard":"fn is_netscape_line(line: &str) -> bool {\n    let f: Vec<&str> = line.trim().split('\\t').collect();\n    f.len() >= 7 && !f[5].is_empty() && !f[6].is_empty()\n}","tryCatchPattern":null,"preventionTips":["Always export cookies with a 'cookies.txt' (Netscape) browser extension, never the JSON export.","Open the file before importing and confirm lines have 7 tab-separated fields.","Check the file is non-empty and not an HTML page accidentally saved as .txt.","Keep cookie exports fresh; expired cookies still parse but will fail later at the HTTP layer."],"tags":["cookies","parse-error","netscape-format","validation"],"backgroundTag":"invalid-argument-format","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"}