flxzt/rnote · error · anyhow::Error

image is not a JSON object.

Error message

image is not a JSON object.

What it means

Thrown in TryFrom<RnoteFileMaj0Min13>::try_from when bitmapimage.image exists but is not a JSON object. The migration chains .as_object_mut() to reach image.rectangle for the transform-to-affine conversion; a non-object 'image' (string/array/number) makes that impossible and aborts the upgrade.

Solutions

  1. Fix the file JSON so bitmapimage.image is an object containing 'rectangle'.
  2. Restore from a backup and re-save the note in the app.
  3. Correct the generating/exporting tool to serialize image as an object.
  4. Make the migration tolerant: skip components whose image is malformed and collect a report instead of failing.

Example fix

// before
.as_object_mut().ok_or(anyhow!("image is not a JSON object."))?
// after: validate shape first
if !bitmapimage["image"].is_object() {
    anyhow::bail!("malformed legacy file: bitmapimage.image must be an object");
}
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: Migrating maj0min13 -> maj0min15 where stroke_components[*].value.bitmapimage.image is a non-object JSON value.

Common situations: Corrupted legacy files; files hand-edited so 'image' holds a scalar or array; buggy third-party rnote generators.

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

Appendix: source

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

                        .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'."))?,
                )?;
            }
        }

        //dbg!(&value);

        Ok(Self {
            engine_snapshot: value.engine_snapshot,
        })
    }
}

View on GitHub (pinned to bbc5354502)