tonhowtf/omniget · error

nenhum trecho para extrair

Error message

nenhum trecho para extrair

What it means

After computing extraction groups (per split mode), if the groups vec is empty the tool throws "nenhum trecho para extrair" ("no segment to extract"). This guards the range-mode branch where parse_ranges produced page lists but the mode mapping yielded nothing to write.

Solutions

  1. Check opts.mode is one of the supported values ("each", "every", or the range mode) — typos fall through to range parsing.
  2. Provide a non-empty, valid ranges string when not using each/every modes.
  3. Validate groups/ranges in the caller before invoking split.

Example fix

// before
SplitOptions { mode: "rangse".into(), ranges: "".into(), .. }

// after
SplitOptions { mode: "ranges".into(), ranges: "1-3".into(), .. }
Defensive patterns

Strategy: validation

Validate before calling

const MODES: [&str; 3] = ["each", "every", "ranges"];
if !MODES.contains(&opts.mode.as_str()) {
    return Err(format!("unknown split mode: {}", opts.mode));
}
if opts.mode == "ranges" && !has_pages(&opts.ranges) {
    return Err("ranges mode requires a valid page-range string");
}

Type guard

fn is_valid_mode(m: &str) -> bool { matches!(m, "each" | "every" | "ranges") }

Try / catch

match split(&opts, &progress) {
    Ok(out) => use(out),
    Err(e) if e.to_string().contains("nenhum trecho") => {
        eprintln!("mode '{}' with ranges '{}' produced nothing", opts.mode, opts.ranges);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling split with mode "ranges" and an opts.ranges string that normalizes to an empty groups vec; effectively any ranges value that yields no extractable segment while not failing earlier in parse_ranges.

Common situations: Ranges string consisting only of separators (",," or " - ") that collapses to an empty name/list; mode string typo'd so it falls through to the default range branch with an unusable ranges value.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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

Appendix: source

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

                .map(|c| (format!("p{:03}-{:03}", c[0], c[c.len() - 1]), c.to_vec()))
                .collect()
        }
        "ranges" => opts
            .ranges
            .split(';')
            .map(str::trim)
            .filter(|s| !s.is_empty())
            .map(|s| {
                parse_ranges(s, total).map(|pages| (s.replace(' ', "").replace(',', "_"), pages))
            })
            .collect::<anyhow::Result<Vec<_>>>()?,
        _ => vec![(
            opts.ranges.replace(' ', "").replace(',', "_"),
            parse_ranges(&opts.ranges, total)?,
        )],
    };
    if groups.is_empty() {
        return Err(anyhow!("nenhum trecho para extrair"));
    }
    let dir = out_dir_for(input, &opts.output_dir);
    std::fs::create_dir_all(&dir)?;
    let base = stem(input);
    let mut outputs = Vec::new();
    let n = groups.len() as u64;
    for (i, (label, pages)) in groups.iter().enumerate() {
        report(progress, "progress", i as u64, Some(n), Some(label.clone()));
        let dest = Document::new(api)?;
        dest.import(&src, pages)?;
        let path = unique(dir.join(format!("{} {}.pdf", base, label)));
        dest.save(&path)?;
        outputs.push(path.to_string_lossy().to_string());
    }
    report(progress, "done", n, Some(n), None);
    Ok(PdfOuts {
        outputs,
        pages: total,

View on GitHub (pinned to 8600b91f42)