{"record":{"id":"778b702a9fc82d66","repo":"bevyengine/bevy","slug":"could-not-construct-an-unevencore","errorCode":null,"errorMessage":"Could not construct an UnevenCore","messagePattern":"Could not construct an UnevenCore","errorType":"exception","errorClass":"UnevenCoreError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/curve/cores.rs","lineNumber":344,"sourceCode":"#[cfg_attr(feature = \"bevy_reflect\", derive(Reflect))]\npub struct UnevenCore<T> {\n    /// The times for the samples of this curve.\n    ///\n    /// # Invariants\n    /// This must always have a length of at least 2, be sorted, and have no\n    /// duplicated or non-finite times.\n    pub times: Vec<f32>,\n\n    /// The samples corresponding to the times for this curve.\n    ///\n    /// # Invariants\n    /// This must always have the same length as `times`.\n    pub samples: Vec<T>,\n}\n\n/// An error indicating that an [`UnevenCore`] could not be constructed.\n#[derive(Debug, Error)]\n#[error(\"Could not construct an UnevenCore\")]\npub enum UnevenCoreError {\n    /// Not enough samples were provided.\n    #[error(\n        \"Need at least two unique samples to create an UnevenCore, but {samples} were provided\"\n    )]\n    NotEnoughSamples {\n        /// The number of samples that were provided.\n        samples: usize,\n    },\n}\n\n#[cfg(feature = \"alloc\")]\nimpl<T> UnevenCore<T> {\n    /// Create a new [`UnevenCore`]. The given samples are filtered to finite times and\n    /// sorted internally; if there are not at least 2 valid timed samples, an error will be\n    /// returned.\n    pub fn new(timed_samples: impl IntoIterator<Item = (f32, T)>) -> Result<Self, UnevenCoreError> {\n        // Filter out non-finite sample times first so they don't interfere with sorting/deduplication.","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/curve/cores.rs#L326-L362","documentation":"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.","triggerScenarios":"UnevenCore::new(timed_samples) or UnevenSampleCurve::new(timed_samples) failing, then being logged with {} or stringified, producing only 'Could not construct an UnevenCore'.","commonSituations":"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.","solutions":["Match on UnevenCoreError::NotEnoughSamples { samples } to surface how many samples survived filtering.","Log with {:?} to see the variant and payload.","Fix the underlying cause: at least 2 samples with unique finite times must remain after NaN/INF filtering and dedup (see sibling entry)."],"exampleFix":"// before\nlet core = UnevenCore::new(samples).map_err(|e| anyhow!(\"curve failed: {e}\"))?; // generic message\n\n// after\nlet core = match UnevenCore::new(samples) {\n    Ok(core) => core,\n    Err(UnevenCoreError::NotEnoughSamples { samples }) => {\n        return Err(anyhow!(\"timed curve needs >= 2 unique finite times, had {samples}\"));\n    }\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match UnevenCore::new(timed_samples) {\n    Ok(core) => core,\n    Err(UnevenCoreError::NotEnoughSamples { samples }) => {\n        warn!(\"timed curve needs >= 2 unique finite samples, had {samples}\");\n        return Ok(());\n    }\n}","preventionTips":["Match the NotEnoughSamples variant to keep the sample count visible in logs.","Centralize UnevenCore construction so every call site shares the same logging and fallback.","Prefer SampleCurve/UnevenSampleCurve helpers and handle their Result uniformly."],"tags":["rust","bevy","math","curve","runtime","error-matching"],"backgroundTag":"curve-core-construction-failed","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}