tonhowtf/omniget · error

escolha o PDF

Error message

escolha o PDF

What it means

Input validation at the entry of run(), the PDF redaction driver: when opts.input is empty or whitespace-only, the run aborts before opening any document. It is a generic guard on the user-supplied input path — it fires when the redaction operation is started without a PDF file chosen.

Solutions

  1. Populate opts.input with the selected PDF path before calling run
  2. Disable the redact action in the UI until a file is chosen
  3. Validate input non-empty at the command boundary

Example fix

// before
let opts = Options { input: String::new(), .. };
run(&opts, &progress)?;
// after
if picked_path.is_empty() { bail!("select a PDF"); }
let opts = Options { input: picked_path, .. };
run(&opts, &progress)?;
Defensive patterns

Strategy: validation

Validate before calling

if opts.input.trim().is_empty() { bail!("select a PDF"); }

Type guard

fn has_input(o: &Options) -> bool { !o.input.trim().is_empty() }

Prevention

When it happens

Trigger: Calling run(&opts, ...) with opts.input == "" or " ".

Common situations: UI invoked the redact command before a file was selected; Options constructed with the input field left unset; file path cleared between selection and run.

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/b2bce16339668801. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/pdf_redact.rs:835

        let (cx, cy, w) = *visible.get(i)?;
        if any_inside(rects, cx, cy) {
            Some(w.max(0.0))
        } else {
            None
        }
    };
    let (mut new_ops, removed, _) = strip_glyphs(&ops, &is_two, &mut plan);
    if bar {
        new_ops.extend(bar_ops(rects, [0.0, 0.0, 0.0]));
    }
    set_content(doc, page_id, new_ops)?;
    drop_annots(doc, page_id, rects);
    Ok((true, removed, format!("{} caracteres apagados", removed)))
}

pub fn run(opts: &Options, progress: &super::ProgressFn) -> anyhow::Result<RedactResult> {
    if opts.input.trim().is_empty() {
        return Err(anyhow!("escolha o PDF"));
    }
    let pw = if opts.password.is_empty() {
        None
    } else {
        Some(opts.password.as_str())
    };
    let dpi = if opts.dpi == 0 { 150 } else { opts.dpi };
    let quality = if opts.quality == 0 { 88 } else { opts.quality };

    report(progress, "progress", 0, 4, Some("lendo o PDF".into()));
    let pages = pdf::read_raw_chars(&opts.input, pw, "")?;
    let total_pages = pages.len();
    let wanted = pdf::parse_ranges(&opts.pages, total_pages)?;
    let (rects, terms_found) = plan_rects(&pages, opts, &wanted);
    if rects.is_empty() {
        return Err(anyhow!(
            "nada para tarjar: marque uma região ou digite um termo"
        ));

View on GitHub (pinned to 8600b91f42)