Skip to content

fix(poly): typed errors for MultilinearPolynomial TryFrom impls#1380

Open
vikions wants to merge 1 commit intoa16z:mainfrom
vikions:fix/multilinear-polynomial-error-types
Open

fix(poly): typed errors for MultilinearPolynomial TryFrom impls#1380
vikions wants to merge 1 commit intoa16z:mainfrom
vikions:fix/multilinear-polynomial-error-types

Conversation

@vikions
Copy link
Copy Markdown

@vikions vikions commented Mar 27, 2026

Replaces type Error = () with a typed MultilinearPolynomialError enum across all 9 TryFrom<&MultilinearPolynomial<F>> implementations, resolving the // TODO(moodlezoup) markers.

Adds MultilinearPolynomialError::WrongVariant { expected, got } with Display and std::error::Error impls, and a private variant_name() helper to report the actual variant on mismatch.

Replace `type Error = ()` with typed `MultilinearPolynomialError` enum
in all 9 TryFrom<&MultilinearPolynomial<F>> implementations.

Adds:
- `MultilinearPolynomialError::WrongVariant { expected, got }` with
  Display and std::error::Error impls
- Private `variant_name()` helper on MultilinearPolynomial

Resolves TODO(moodlezoup) at lines 484-572.
Copy link
Copy Markdown
Collaborator

@0xAndoroid 0xAndoroid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just one nit

Comment on lines +500 to +519
#[derive(Debug, Clone, PartialEq)]
pub enum MultilinearPolynomialError {
WrongVariant {
expected: &'static str,
got: &'static str,
},
}

impl std::fmt::Display for MultilinearPolynomialError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::WrongVariant { expected, got } => {
write!(f, "expected {expected} variant, got {got}")
}
}
}
}

impl std::error::Error for MultilinearPolynomialError {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's derive the thiserror::Error

Suggested change
#[derive(Debug, Clone, PartialEq)]
pub enum MultilinearPolynomialError {
WrongVariant {
expected: &'static str,
got: &'static str,
},
}
impl std::fmt::Display for MultilinearPolynomialError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::WrongVariant { expected, got } => {
write!(f, "expected {expected} variant, got {got}")
}
}
}
}
impl std::error::Error for MultilinearPolynomialError {}
#[derive(Error, Debug, Clone, PartialEq)]
pub enum MultilinearPolynomialError {
#[error("Invalid MultilinearPolynomial: expected {expected}, got {got}")]
WrongVariant {
expected: &'static str,
got: &'static str,
},
}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants