tonhowtf/omniget · error

escolha pelo menos dois PDFs

Error message

escolha pelo menos dois PDFs

What it means

merge() requires at least two input PDFs to combine. With fewer than 2 entries in MergeOptions.inputs it throws "escolha pelo menos dois PDFs" ("choose at least two PDFs") before opening any document.

Solutions

  1. Pass at least two existing PDF paths in MergeOptions.inputs.
  2. Disable/guard the merge action in the UI until inputs.len() >= 2.
  3. If merging a single file is intentional, skip merge and copy the file instead.

Example fix

// before
merge(&MergeOptions { inputs: vec![a], .. }, progress)

// after
if inputs.len() >= 2 { merge(&MergeOptions { inputs, .. }, progress) } else { /* copy or error in UI */ }
Defensive patterns

Strategy: validation

Validate before calling

if opts.inputs.len() < 2 {
    return Err("select at least two PDFs to merge");
}
if opts.inputs.iter().any(|p| !std::path::Path::new(p).is_file()) {
    return Err("all inputs must be existing files");
}

Try / catch

match merge(&opts, &progress) {
    Ok(out) => println!("merged -> {}", out.output),
    Err(e) if e.to_string().contains("pelo menos dois") => {
        eprintln!("Need 2+ PDFs; got {}", opts.inputs.len());
    }
    Err(e) => eprintln!("merge failed: {e}"),
}

Prevention

When it happens

Trigger: Calling merge with an empty inputs vec, or with exactly one PDF path in MergeOptions.inputs.

Common situations: UI allowing the merge action with one file selected; drag-and-drop dropping only one file; a filter step silently removing invalid paths leaving 0 or 1 entries.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/d738fb17f0d88b95. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:814

// ── Juntar ─────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Deserialize)]
pub struct MergeOptions {
    pub inputs: Vec<String>,
    pub output: String,
}

#[derive(Debug, Clone, Serialize)]
pub struct PdfOut {
    pub output: String,
    pub pages: usize,
    pub bytes: u64,
}

pub fn merge(opts: &MergeOptions, progress: &super::ProgressFn) -> anyhow::Result<PdfOut> {
    if opts.inputs.len() < 2 {
        return Err(anyhow!("escolha pelo menos dois PDFs"));
    }
    let api = api()?;
    let _g = OPS.lock().unwrap_or_else(|p| p.into_inner());
    let dest = Document::new(api)?;
    let total = opts.inputs.len() as u64;
    for (i, input) in opts.inputs.iter().enumerate() {
        report(
            progress,
            "progress",
            i as u64,
            Some(total),
            Some(input.clone()),
        );
        let src = Document::open(api, Path::new(input), None)?;
        let all: Vec<usize> = (1..=src.pages()).collect();
        if !all.is_empty() {
            dest.import(&src, &all)?;
        }

View on GitHub (pinned to 8600b91f42)