bevyengine/bevy · error · UnevenCoreError

Could not construct an UnevenCore

Error message

Could not construct an UnevenCore

What it means

UnevenCoreError is the error type returned by UnevenCore::new (and UnevenSampleCurve::new and UnevenSampleAutoCurve::new, which forward it). The enum has a single variant today (NotEnoughSamples), so this umbrella message appears when the error is displayed without matching the variant — e.g. formatted with {} through anyhow — hiding the sample count detail.

Source

Thrown at crates/bevy_math/src/curve/cores.rs:344

#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
pub struct UnevenCore<T> {
    /// The times for the samples of this curve.
    ///
    /// # Invariants
    /// This must always have a length of at least 2, be sorted, and have no
    /// duplicated or non-finite times.
    pub times: Vec<f32>,

    /// The samples corresponding to the times for this curve.
    ///
    /// # Invariants
    /// This must always have the same length as `times`.
    pub samples: Vec<T>,
}

/// An error indicating that an [`UnevenCore`] could not be constructed.
#[derive(Debug, Error)]
#[error("Could not construct an UnevenCore")]
pub enum UnevenCoreError {
    /// Not enough samples were provided.
    #[error(
        "Need at least two unique samples to create an UnevenCore, but {samples} were provided"
    )]
    NotEnoughSamples {
        /// The number of samples that were provided.
        samples: usize,
    },
}

#[cfg(feature = "alloc")]
impl<T> UnevenCore<T> {
    /// Create a new [`UnevenCore`]. The given samples are filtered to finite times and
    /// sorted internally; if there are not at least 2 valid timed samples, an error will be
    /// returned.
    pub fn new(timed_samples: impl IntoIterator<Item = (f32, T)>) -> Result<Self, UnevenCoreError> {
        // Filter out non-finite sample times first so they don't interfere with sorting/deduplication.

View on GitHub (pinned to 396ca72708)

Solutions

  1. Match on UnevenCoreError::NotEnoughSamples { samples } to surface how many samples survived filtering.
  2. Log with {:?} to see the variant and payload.
  3. Fix the underlying cause: at least 2 samples with unique finite times must remain after NaN/INF filtering and dedup (see sibling entry).

Example fix

// before
let core = UnevenCore::new(samples).map_err(|e| anyhow!("curve failed: {e}"))?; // generic message

// after
let core = match UnevenCore::new(samples) {
    Ok(core) => core,
    Err(UnevenCoreError::NotEnoughSamples { samples }) => {
        return Err(anyhow!("timed curve needs >= 2 unique finite times, had {samples}"));
    }
};
Defensive patterns

Strategy: try-catch

Try / catch

match UnevenCore::new(timed_samples) {
    Ok(core) => core,
    Err(UnevenCoreError::NotEnoughSamples { samples }) => {
        warn!("timed curve needs >= 2 unique finite samples, had {samples}");
        return Ok(());
    }
}

Prevention

When it happens

Trigger: UnevenCore::new(timed_samples) or UnevenSampleCurve::new(timed_samples) failing, then being logged with {} or stringified, producing only 'Could not construct an UnevenCore'.

Common situations: Error logs from animation/keyframe curve builders that use anyhow and lose the variant payload; wrapping the error in a custom error type whose Display just forwards the enum's Display.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/778b702a9fc82d66. Report an issue: GitHub.