flxzt/rnote · error · anyhow::Error

Creating Pdf instance failed, Err

Error message

Creating Pdf instance failed, Err: {err:?}

What it means

Thrown when `hayro_syntax::Pdf::new_with_password` fails to construct a Pdf instance from the loaded bytes with the provided password. This means the bytes are not a parsable PDF or the password is wrong, so the import is aborted with a debug-formatted error from the hayro parser.

Solutions

  1. Re-enter the correct PDF password (verify with the document owner).
  2. Check `file` is a valid PDF: `file.query_info("standard::content-type")` should be `application/pdf` before import.
  3. Open the PDF in another viewer to confirm the file is not corrupted; re-obtain or repair the file.
  4. Try opening without a password if the PDF may not be encrypted; use `Pdf::new` and inspect the encryption error.

Example fix

// before
let pdf = hayro_syntax::Pdf::new_with_password(pdf_data, password)
    .map_err(|err| anyhow!("Creating Pdf instance failed, Err: {err:?}"))?;
// after
let pdf = match hayro_syntax::Pdf::new_with_password(pdf_data, password) {
    Ok(pdf) => pdf,
    Err(err) => {
        appwindow.overlays().dispatch_toast_error(&gettext("Wrong password or unreadable PDF"));
        return Err(anyhow!("PDF open with password failed: {err:?}"));
    }
};
Defensive patterns

Strategy: try-catch

Validate before calling

let ctype = input_file.query_info("standard::content-type", gio::FileQueryInfoFlags::NONE, gio::Cancellable::NONE)?
    .content_type();
if ctype != Some("application/pdf".into()) { bail!("not a PDF file"); }

Try / catch

match hayro_syntax::Pdf::new_with_password(data, pwd) {
    Ok(pdf) => proceed(pdf),
    Err(err) => show_toast("Wrong password or unreadable PDF"),
}

Prevention

When it happens

Trigger: Calling `dialog_import_pdf_w_prefs` with a password-protected PDF where the supplied password is incorrect, or with a corrupted/non-PDF file that hayro's parser rejects during `new_with_password`.

Common situations: User typed a wrong password into the PDF password prompt; file truncated during download/transfer; the 'PDF' is actually a renamed image or HTML file; PDF encrypted with an algorithm hayro does not support.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08). Data as JSON: /api/errors/016ce29d089a269a. Report an issue: GitHub.

Appendix: source

Thrown at crates/rnote-ui/src/dialogs/import.rs:411

    ));

    pdf_import_adjust_document_row.connect_active_notify(clone!(
        #[weak]
        appwindow,
        move |row| {
            appwindow
                .engine_config()
                .write()
                .import_prefs
                .pdf_import_prefs
                .adjust_document = row.is_active();
        }
    ));

    let pdf_data = Arc::new(input_file.load_bytes_future().await?.0.to_vec());
    let pdf = if let Some(password) = password.as_ref() {
        hayro_syntax::Pdf::new_with_password(pdf_data, password)
            .map_err(|err| anyhow!("Creating Pdf instance failed, Err: {err:?}"))?
    } else {
        hayro_syntax::Pdf::new(pdf_data)
            .map_err(|err| anyhow!("Creating Pdf instance failed, Err: {err:?}"))?
    };
    let pdf_metadata = pdf.metadata();

    let file_name = input_file.basename().map_or_else(
        || gettext("- no file name -"),
        |s| s.to_string_lossy().to_string(),
    );
    let title = pdf_metadata
        .title
        .to_owned()
        .and_then(|s| String::from_utf8(s).ok())
        .unwrap_or_else(|| gettext("- no title -"));
    let author = pdf_metadata
        .author
        .to_owned()

View on GitHub (pinned to bbc5354502)