emilk/egui · error

Multiple SnapshotResults were dropped without being handled

Error message

Multiple SnapshotResults were dropped without being handled.

In order to allow consistent snapshot updates, all snapshot results within a test should be merged in a single SnapshotResults instance.
Usually this is handled internally in a harness. If you have multiple harnesses, you can merge the results using `Harness::take_snapshot_results` and `SnapshotResults::extend`.

The SnapshotResult was constructed at {}
                    

What it means

When a SnapshotResults is dropped unhandled, a thread-local counter tracks how many such drops occurred; if two or more happen in one test, this panic fires. It exists because multiple separate SnapshotResults instances break consistent snapshot updating (e.g. one instance may trigger an update while another still reports a mismatch). The message tells you to merge all results into a single SnapshotResults per test.

Source

Thrown at crates/egui_kittest/src/snapshot.rs:983

        #[expect(clippy::manual_assert)]
        if self.has_errors() {
            panic!("{}", self);
        }

        thread_local! {
            static UNHANDLED_SNAPSHOT_RESULTS_COUNTER: core::cell::RefCell<usize> = const { core::cell::RefCell::new(0) };
        }

        if !self.handled {
            let count = UNHANDLED_SNAPSHOT_RESULTS_COUNTER.with(|counter| {
                let mut count = counter.borrow_mut();
                *count += 1;
                *count
            });

            #[expect(clippy::manual_assert)]
            if count >= 2 {
                panic!(
                    "
Multiple SnapshotResults were dropped without being handled.

In order to allow consistent snapshot updates, all snapshot results within a test should be merged in a single SnapshotResults instance.
Usually this is handled internally in a harness. If you have multiple harnesses, you can merge the results using `Harness::take_snapshot_results` and `SnapshotResults::extend`.

The SnapshotResult was constructed at {}
                    ",
                    self.location
                );
            }
        }
    }
}

View on GitHub (pinned to 441971a776)

Solutions

  1. Collect each harness's results with Harness::take_snapshot_results and merge them all into one SnapshotResults with SnapshotResults::extend before the test ends.
  2. Call assert_result (or equivalent) on the merged SnapshotResults so nothing is dropped unhandled.
  3. Restructure the test to use a single harness when possible, avoiding multiple independent SnapshotResults.

Example fix

// before: two harnesses, results dropped independently
let mut h1 = Harness::new(...); h1.image_snapshot("a");
let mut h2 = Harness::new(...); h2.image_snapshot("b");

// after: merge into a single SnapshotResults
let mut results = h1.take_snapshot_results();
results.extend(h2.take_snapshot_results());
results.assert_result();
Defensive patterns

Strategy: validation

Validate before calling

// ensure a single merged SnapshotResults per test
let mut all = harness1.take_snapshot_results();
all.extend(harness2.take_snapshot_results());
assert_eq!(dropped_unhandled_results_expected(), 0);
all.assert_result();

Prevention

When it happens

Trigger: Dropping two or more SnapshotResults without handling them in the same test thread — typically created by multiple Harnesses (or standalone snapshot calls) in one #[test] whose results are never taken/merged.

Common situations: A test with two or more harnesses each doing image_snapshot but never merging results; refactoring a test to spawn several harnesses without updating the result-collection logic; helper functions that each create their own harness.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of emilk/egui@441971a776 (2026-09-12). Data as JSON: /api/errors/a3996f9ecb589a55. Report an issue: GitHub.