Skip to content

Add std::error::Error impls for error types #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2025
Merged

Conversation

ronnodas
Copy link
Contributor

@ronnodas ronnodas commented Feb 5, 2025

The trait is meant for error types. This also makes it more convenient for users wrapping biblatex's error types into their own errors and using the thiserror crate to derive error traits.

Copy link

@jonaspleyer jonaspleyer left a comment

Choose a reason for hiding this comment

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

I have just opened another PR which basically does the same. You got there first. LGTM

@anwaralameddin
Copy link

Hello, I am running into the same issue when wrapping biblatex error types with a structure implementing the thiserror::Error trait. Currently, using the main branch, the following code errors

use thiserror::Error;

#[derive(Debug, Error)]
pub enum MyError {
    #[error("TypeError: {0}")]
    TypeError (#[from] TypeError),
}

Temporally, I am using the following instead

use thiserror::Error;

#[derive(Debug, Error)]
pub enum MyError {
    #[error("TypeError: {0}")]
    TypeError (TypeError),
}

impl From<TypeError> for MyError {
    fn from(err: TypeError) -> Self {
        BibError::TypeError(err)
    }
}

It would be helpful if this PR could be progressed to avoid the need for this, especially since the issue applies also to RetrievalError and ParseError.

Also, in line with the OP, in general, error types are expected to implement the std::error::Error trait.

Copy link
Contributor

@PgBiel PgBiel left a comment

Choose a reason for hiding this comment

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

Thanks!

@PgBiel PgBiel merged commit 2567397 into typst:main May 14, 2025
2 checks passed
@PgBiel
Copy link
Contributor

PgBiel commented May 14, 2025

Thank you!

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.

4 participants