{"record":{"id":"0bc06ccb71762a39","repo":"tonhowtf/omniget","slug":"escolha-pelo-menos-uma-imagem","errorCode":null,"errorMessage":"escolha pelo menos uma imagem","messagePattern":"escolha pelo menos uma imagem","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":1024,"sourceCode":"        None\n    };\n    Ok(TextResult {\n        text,\n        output,\n        pages: pages.len(),\n    })\n}\n\n// ── Imagens → PDF ──────────────────────────────────────────────────────\n\npub fn images_to_pdf(\n    inputs: &[String],\n    output: &str,\n    quality: u8,\n    progress: &super::ProgressFn,\n) -> anyhow::Result<PdfOut> {\n    if inputs.is_empty() {\n        return Err(anyhow!(\"escolha pelo menos uma imagem\"));\n    }\n    let quality = if quality == 0 { 90 } else { quality };\n    let mut jpegs = Vec::with_capacity(inputs.len());\n    let n = inputs.len() as u64;\n    for (i, input) in inputs.iter().enumerate() {\n        report(progress, \"progress\", i as u64, Some(n), Some(input.clone()));\n        let data = std::fs::read(input).map_err(|e| anyhow!(\"nao leu {}: {}\", input, e))?;\n        if jpeg_pdf::is_jpeg(&data) {\n            jpegs.push(data);\n        } else {\n            let img = image::load_from_memory(&data)\n                .map_err(|e| anyhow!(\"{}: {}\", input, e))?\n                .to_rgb8();\n            jpegs.push(encode(&img, \"jpg\", quality)?);\n        }\n    }\n    let pdf = jpeg_pdf::build_pdf(&jpegs)?;\n    let out = unique(PathBuf::from(output.trim()));","sourceCodeStart":1006,"sourceCodeEnd":1042,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L1006-L1042","documentation":"Input validation at the top of images_to_pdf(): the function requires at least one image path in inputs; with an empty slice it errors immediately before computing quality defaults or converting any JPEG. It fires when the images-to-PDF operation is invoked with no input images selected.","triggerScenarios":"Calling the internal img->PDF builder with inputs: &[] — e.g. the caller filtered out all non-image files, or the UI submitted the conversion with no files selected.","commonSituations":"File picker returning empty selection; extension filter removing everything (only .png/.jpg allowed but user picked .webp which was filtered elsewhere); drag-drop with no files.","solutions":["Pass at least one image path in inputs.","Guard the action in the UI until at least one image is selected.","If files were filtered out, inform the user why instead of calling with an empty vec."],"exampleFix":"// before\nbuild_pdf_from_images(&[], out, quality, progress)\n\n// after\nif !images.is_empty() { build_pdf_from_images(&images, out, quality, progress) } else { /* surface selection error */ }","handlingStrategy":"validation","validationCode":"if inputs.is_empty() {\n    return Err(\"select at least one image\");\n}\nfor p in inputs {\n    if !std::path::Path::new(p).is_file() {\n        return Err(format!(\"not a file: {}\", p));\n    }\n}","typeGuard":null,"tryCatchPattern":"if inputs.is_empty() {\n    eprintln!(\"no images selected\");\n} else {\n    match images_to_pdf(&inputs, output, quality, &progress) {\n        Ok(out) => use(out),\n        Err(e) => eprintln!(\"conversion failed: {e}\"),\n    }\n}","preventionTips":["Guard the convert action until at least one image is picked.","Report filtered-out files to the user instead of silently dropping them.","Keep the raw selection count visible in the UI."],"tags":["pdf","images","argument-validation","rust"],"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"}