bevyengine/bevy · error · EvenCoreError
Could not construct an EvenCore
Error message
Could not construct an EvenCore
What it means
EvenCoreError is the umbrella error returned by EvenCore::new (and APIs that build evenly-sampled curves on top of it, like EvenSampleCurve/SampleCurve constructors). The enum-level message appears when the error is displayed without matching a variant — e.g. logged via {} or converted to a string — while the concrete cause (too few samples or unbounded domain) is in the variant. Check the variants NotEnoughSamples and UnboundedDomain for specifics.
Source
Thrown at crates/bevy_math/src/curve/cores.rs:140
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
pub struct EvenCore<T> {
/// The domain over which the samples are taken, which corresponds to the domain of the curve
/// formed by interpolating them.
///
/// # Invariants
/// This must always be a bounded interval; i.e. its endpoints must be finite.
pub domain: Interval,
/// The samples that are interpolated to extract values.
///
/// # Invariants
/// This must always have a length of at least 2.
pub samples: Vec<T>,
}
/// An error indicating that an [`EvenCore`] could not be constructed.
#[derive(Debug, Error)]
#[error("Could not construct an EvenCore")]
pub enum EvenCoreError {
/// Not enough samples were provided.
#[error("Need at least two samples to create an EvenCore, but {samples} were provided")]
NotEnoughSamples {
/// The number of samples that were provided.
samples: usize,
},
/// Unbounded domains are not compatible with `EvenCore`.
#[error("Cannot create an EvenCore over an unbounded domain")]
UnboundedDomain,
}
#[cfg(feature = "alloc")]
impl<T> EvenCore<T> {
/// Create a new [`EvenCore`] from the specified `domain` and `samples`. The samples are
/// regarded to be evenly spaced within the given domain interval, so that the outermost
/// samples form the boundary of that interval. An error is returned if there are not atView on GitHub (pinned to 396ca72708)
Solutions
- Match on the variant to get the real cause: NotEnoughSamples { samples } vs UnboundedDomain.
- Use {:?} (Debug) in logs — it prints the variant and its payload.
- Fix the underlying condition per the variant's documentation (see the sibling error entries).
Example fix
// before
let curve = EvenCore::new(domain, samples).map_err(|e| format!("curve failed: {e}"))?; // "Could not construct an EvenCore"
// after
let core = match EvenCore::new(domain, samples) {
Ok(core) => core,
Err(EvenCoreError::NotEnoughSamples { samples }) => {
return Err(format!("need >= 2 samples, got {samples}").into());
}
Err(EvenCoreError::UnboundedDomain) => {
return Err("domain must be bounded".into());
}
}; Defensive patterns
Strategy: try-catch
Try / catch
match EvenCore::new(domain, samples) {
Ok(core) => core,
Err(e @ (EvenCoreError::NotEnoughSamples { .. } | EvenCoreError::UnboundedDomain)) => {
warn!("even core rejected: {e:?}");
return Ok(());
}
} Prevention
- Always match EvenCoreError variants instead of displaying the enum, so the real cause is never hidden.
- In logs use {:?} for these error enums.
- Wrap curve construction in one place with a single, well-logged match so every failure mode is observable.
When it happens
Trigger: Any call to EvenCore::new(domain, samples), or higher-level constructors that wrap it, failing for either reason; then formatting the error with {} instead of {:?} or matching variants, so only the umbrella text is visible.
Common situations: Logging curve-construction failures in a plugin and only seeing the generic message; chaining errors with anyhow/eyre where the enum Display is what gets printed.
Related errors
- Could not construct an UnevenCore
- Could not create a ChunkedUnevenCore
- Not enough data to build curve: needed at least {expected} c
- Need at least two samples to create an EvenCore, but {sample
- Cannot create an EvenCore over an unbounded domain
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/47fe973b2cbf5724.
Report an issue: GitHub.