Skip to content

Failed error type is opaque: DenseMatrix::new failures carry no diagnostic detail #460

Description

@genefold-ai

Problem

DenseMatrix::new(nrows, ncols, values, column_major) -> Result<Self, Failed> fails with Failed, which carries no structured information: which dimension constraint was violated, what was received, what was expected. Every dimension bug becomes guesswork at the call site.

Real example from downstream debugging (genefold): a transpose bug in test fixtures (from_iterator axis 0 vs 1) surfaced as a bare Failed from DenseMatrix::new deep inside a build path. Diagnosing required re-deriving the expected element count by hand.

Proposal

Introduce structured variants while keeping Failed as a legacy alias:

pub enum MatrixError {
    DimensionMismatch { rows: usize, cols: usize, expected_len: usize, got: usize },
    EmptyInput,
    NaNValue { index: (usize, usize) },
}

Minimum viable step: make Failed's Display include received vs expected sizes for the common length-mismatch case. That single change resolves most debugging pain without a breaking API change.

Note

Same reasoning applies to other constructors returning Failed (from_2d_vec, from_iterator): they know expected vs actual element counts at the failure point and currently discard them.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions