{"record":{"id":"85157a9e06cc300f","repo":"tonhowtf/omniget","slug":"escolha-a-pasta-do-arquivo","errorCode":null,"errorMessage":"escolha a pasta do arquivo","messagePattern":"escolha a pasta do arquivo","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/yt_archive.rs","lineNumber":483,"sourceCode":"fn has_session(opts: &Options) -> bool {\n    opts.session_netscape\n        .as_ref()\n        .map(|s| !s.trim().is_empty())\n        .unwrap_or(false)\n}\n\n/// Lê o estado gravado sem tocar na rede — é o que a tela mostra ao abrir.\npub fn state(dest: &str) -> anyhow::Result<ArchiveResult> {\n    let dir = PathBuf::from(dest.trim());\n    let st = load_state(&dir).ok_or_else(|| anyhow!(\"não há arquivo em andamento nessa pasta\"))?;\n    Ok(result_of(&dir, &st, false, false))\n}\n\n/// Enumera a coleção e funde com o estado, sem baixar nada.\npub async fn scan(opts: &Options, progress: &super::ProgressFn) -> anyhow::Result<ArchiveResult> {\n    let dest = PathBuf::from(opts.dest.trim());\n    if opts.dest.trim().is_empty() {\n        return Err(anyhow!(\"escolha a pasta do arquivo\"));\n    }\n    std::fs::create_dir_all(&dest)?;\n    let mut st = enumerate(opts, &dest, progress).await?;\n    save_state(&dest, &mut st)?;\n    Ok(result_of(&dest, &st, has_session(opts), false))\n}\n\nasync fn enumerate(\n    opts: &Options,\n    dest: &Path,\n    progress: &super::ProgressFn,\n) -> anyhow::Result<ArchiveState> {\n    super::report(\n        progress,\n        ID,\n        \"progress\",\n        0,\n        None,","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/yt_archive.rs#L465-L501","documentation":"scan validates that opts.dest names a folder before enumerating the collection. If dest is empty (or only whitespace), it throws \"escolha a pasta do arquivo\". This is an upfront input guard so yt-dlp never runs without a target directory.","triggerScenarios":"Calling scan (e.g. from the live_yt_archive_enumerates_a_public_playlist flow or the UI) with Options.dest set to \"\" or whitespace only.","commonSituations":"User clicking enumerate before picking a folder in the UI; frontend passing an unset/unbound form field; tests constructing Options without dest.","solutions":["Set opts.dest to a valid writable folder path before calling scan.","In the UI, disable the enumerate action until a folder is chosen.","Trim and validate the path in the frontend before invoking the command.","If dest comes from config/settings, provide a default download directory."],"exampleFix":"// before\nlet res = yt_archive::scan(&opts, &progress).await?;\n// after\nif opts.dest.trim().is_empty() {\n    eprintln!(\"selecione uma pasta de destino antes de enumerar\");\n    return Ok(());\n}\nlet res = yt_archive::scan(&opts, &progress).await?;","handlingStrategy":"validation","validationCode":"// Rust\nlet dest = opts.dest.trim();\nif dest.is_empty() {\n    return Err(anyhow!(\"selecione a pasta do arquivo antes de enumerar\"));\n}\nif !std::path::Path::new(dest).is_dir() {\n    std::fs::create_dir_all(dest)?;\n}","typeGuard":null,"tryCatchPattern":"match yt_archive::scan(&opts, &progress).await {\n    Ok(r) => r,\n    Err(e) if e.to_string().contains(\"escolha a pasta\") => {\n        eprintln!(\"pasta de destino não definida\");\n        prompt_user_for_folder()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Validate dest in the UI before enabling the enumerate action","Provide a default download directory in settings","Trim paths coming from forms/config to avoid whitespace-only values","Ensure the Options struct is fully populated in tests and callers"],"tags":["validation","argument","yt-archive"],"backgroundTag":"missing-required-argument","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"}