flxzt/rnote · error · anyhow::Error

bitmapimage is not a JSON object.

Error message

bitmapimage is not a JSON object.

What it means

Thrown in TryFrom<RnoteFileMaj0Min13>::try_from when a stroke component's value contains the key 'bitmapimage' but the bound value itself is not a JSON object (e.g. a string, number or array). The migration needs to mutate bitmapimage fields to convert transform matrices, so it requires an object and returns this error otherwise.

Solutions

  1. Open the file JSON and restore 'bitmapimage' to a proper object containing 'image' and 'rectangle' keys.
  2. Recover from a backup or re-save the note from a version that reads the file correctly.
  3. Fix any file-generating tooling to serialize bitmapimage as a struct/object, not a primitive.
  4. Soften the migration to skip invalid bitmapimage entries with a warning instead of erroring.

Example fix

// before
let bitmapimage = bitmapimage.as_object_mut().ok_or(anyhow!("bitmapimage is not a JSON object."))?;
// after (caller-side validation before migration)
if !comp_value["bitmapimage"].is_object() {
    return Err(anyhow!("corrupt file: bitmapimage must be an object"));
}
Defensive patterns

Strategy: validation

Validate before calling

let bi = &comp["value"]["bitmapimage"];
if !bi.is_object() {
    return Err("bitmapimage must be a JSON object".into());
}

Type guard

fn is_bitmapimage(v: &IValue) -> bool {
    v.get("bitmapimage").map_or(false, |b| b.is_object())
}

Try / catch

match RnoteFileMaj0Min15::try_from(file_maj0min13) {
    Ok(f) => f,
    Err(e) if e.to_string().contains("bitmapimage is not a JSON object") => {
        // restore from backup or surface a 'corrupt file' dialog
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Migrating maj0min13 -> maj0min15 where stroke_components[*].value.bitmapimage is a non-object JSON value while the key 'bitmapimage' exists.

Common situations: Corrupted or hand-edited legacy .rnote files; files written by third-party exporters that emit scalar/array payloads under 'bitmapimage'.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at crates/rnote-engine/src/fileformats/rnoteformat/maj0min15.rs:89

                .as_object_mut()
                .ok_or(anyhow!("value is not a JSON object."))?
                .get_mut("vectorimage")
            {
                convert_transform_to_affine_in_obj(
                    vectorimage
                        .as_object_mut()
                        .ok_or(anyhow!("vectorimage is not a JSON object."))?
                        .get_mut("rectangle")
                        .ok_or(anyhow!("vectorimage does not contain 'rectangle'."))?,
                )?;
            } else if let Some(bitmapimage) = value
                .as_object_mut()
                .ok_or(anyhow!("value is not a JSON object."))?
                .get_mut("bitmapimage")
            {
                let bitmapimage = bitmapimage
                    .as_object_mut()
                    .ok_or(anyhow!("bitmapimage is not a JSON object."))?;

                convert_transform_to_affine_in_obj(
                    bitmapimage
                        .get_mut("image")
                        .ok_or(anyhow!("bitmapimage does not contain 'image'."))?
                        .as_object_mut()
                        .ok_or(anyhow!("image is not a JSON object."))?
                        .get_mut("rectangle")
                        .ok_or(anyhow!("image does not contain 'rectangle'."))?,
                )?;
                convert_transform_to_affine_in_obj(
                    bitmapimage
                        .get_mut("rectangle")
                        .ok_or(anyhow!("bitmapimage does not contain 'rectangle'."))?,
                )?;
            }
        }

View on GitHub (pinned to bbc5354502)