Skip to content

Improvements to error handling #633

@sanket1729

Description

@sanket1729

Here is one strategy that I think we should do to improve the ergonomics of errors. Broadly speaking, there are two ways users can interact with secp API.

  1. Users who just bubble up the error.
  2. Users who match on errors on variants and deal with them in some way.

Right now, our API is not the most convenient for users (2). For example, Signature::from_der returns only one error variant but the user is forced to match against all variants.

Proposal

Have each API return a separate error type that does not have any variants that are unreachable. Provide a top level common error type to unify all error types for users who just want to bubble up errors.

pub Error{
	InvalidSig(InvalidSigError),
	PubkeyParseError(PubKeyParseError),
}
impl Signature{
	pub fn from_der() -> Result<.., InvalidSigError>;
}
impl FromStr for PublicKey {
	pub fn from_str() -> Result<..., PubkeyParseError>;
}

impl From<InvalidSigError> for Error {}
impl From<PubkeyParseError> for Error {}

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