Skip to content

Simple API should return finer typed error kind #170

Description

@DarkFenX

This is a follow-up from discussion from #168, and issue #169.

I suggest to redo simple API error type from boxed dyn error to an enum with a few variants:

  • reader error
  • deserializer error
  • <any other struson-specific error variants>
  • misc/custom (with boxed dyn error)

If #169 and this is implemented, initial code I posted to #169 could become super short:

#[derive(thiserror::Error, Debug)]
pub(in crate::phb) enum PhbParseError {
    #[error("reading failed: {0}")]
    ReadFailed(String),
    #[error("parsing failed: {0}")]
    ParseFailed(String),
}
impl From<struson::reader::HybridReaderError> for PhbParseError {
    fn from(error: struson::reader::HybridReaderError) -> Self {
        match error.is_io() {
            true => Self::ReadFailed(error.to_string()),
            false => Self::ParseFailed(error.to_string()),
        }
    }
}

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

    enhancementNew feature or requestfeature:simple-apiIssue or pull related to the "Simple API"

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions