tonhowtf/omniget · error

nenhuma pagina selecionada

Error message

nenhuma pagina selecionada

What it means

parse_ranges converts a user-supplied page-range string (e.g. "1-3,5") into a list of page indices. If the parsed result is empty — because the string is empty, malformed, or references no valid pages — it throws this Portuguese error ("no page selected"). All PDF tools (redaction_check, split, render, to_text, read_pages, read_raw_chars) funnel through it, so this error surfaces whenever a range selector resolves to zero pages.

Solutions

  1. Ensure opts.ranges contains at least one valid page or range token (e.g. "1", "1-3,5").
  2. Treat an empty ranges string as "all pages" by passing "1-<total>" from the caller.
  3. Validate ranges against the document page count before invoking the tool.
  4. Trim and normalize the string (remove stray commas/dashes) before calling.

Example fix

// before
to_text(&TextOptions { ranges: "".into(), .. })

// after
let ranges = if opts.ranges.trim().is_empty() { format!("1-{}", total) } else { opts.ranges.clone() };
to_text(&TextOptions { ranges, .. })
Defensive patterns

Strategy: validation

Validate before calling

let ranges = opts.ranges.trim();
let valid = !ranges.is_empty()
    && ranges.split(',').any(|tok| {
        tok.split('-').filter_map(|p| p.trim().parse::<usize>().ok()).count() > 0
    });
if !valid { return Err("provide at least one page, e.g. '1-3,5'"); }

Type guard

fn has_pages(ranges: &str) -> bool {
    ranges.split(',').any(|tok| {
        tok.split('-').any(|p| p.trim().parse::<usize>().is_ok())
    })
}

Try / catch

match parse_ranges(&opts.ranges, total) {
    Ok(pages) => use(pages),
    Err(e) if e.to_string().contains("nenhuma pagina") => {
        let pages: Vec<usize> = (1..=total).collect(); // fall back to all pages
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling any PDF operation with opts.ranges set to an empty string, whitespace, a token with no digits (e.g. "abc" or "--"), or out-of-bounds page numbers only (e.g. ranges "50-60" on a 10-page PDF, assuming the parser clamps invalid pages out).

Common situations: Users leaving the page-range field blank expecting "all pages"; pasting ranges with invalid separators; UI passing the wrong field (e.g. empty ranges while pages exist); locale issues where a translated range string reaches the parser.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

            } else {
                out.extend((b..=a).rev());
            }
        } else {
            let n: usize = part
                .parse()
                .map_err(|_| anyhow!("pagina invalida: {}", part))?;
            if n == 0 || n > total {
                return Err(anyhow!(
                    "pagina fora do documento ({} paginas): {}",
                    total,
                    n
                ));
            }
            out.push(n);
        }
    }
    if out.is_empty() {
        return Err(anyhow!("nenhuma pagina selecionada"));
    }
    Ok(out)
}

fn stem(path: &Path) -> String {
    path.file_stem()
        .map(|s| s.to_string_lossy().to_string())
        .unwrap_or_else(|| "documento".into())
}

fn out_dir_for(input: &Path, output_dir: &str) -> PathBuf {
    if output_dir.trim().is_empty() {
        input
            .parent()
            .map(Path::to_path_buf)
            .unwrap_or_else(|| PathBuf::from("."))
    } else {
        PathBuf::from(output_dir.trim())

View on GitHub (pinned to 8600b91f42)