Skip to content
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

Change errors to use thiserror #1261

Closed
1 task
hackaugusto opened this issue Feb 27, 2024 · 8 comments
Closed
1 task

Change errors to use thiserror #1261

hackaugusto opened this issue Feb 27, 2024 · 8 comments
Assignees
Milestone

Comments

@hackaugusto
Copy link
Contributor

  • Change the error implementation to use thiserror crate

related: 0xPolygonMiden/miden-node#62

@hackaugusto
Copy link
Contributor Author

thiserror doesn't support no-std

@bitwalker
Copy link
Contributor

That's going to change when the error_in_core feature stabilizes.

In the meantime, we should use this fork. I've introduced it in my assembler changes (hope to have those pushed tonight/tomorrow).

@bobbinth
Copy link
Contributor

That's going to change when the error_in_core feature stabilizes.

Hopefully, this will happen soon - but also I think the timing of this is rather unpredictable.

In the meantime, we should use this fork. I've introduced it in my assembler changes (hope to have those pushed tonight/tomorrow).

Seems like this crate was published just yesterday? I'd be hesitant to use such a new dependency (we try to minimize the number of dependencies in general, and when required use more stable and well-known dependencies). How critical is this to the assembler changes?

@bitwalker
Copy link
Contributor

I mean, we can fork thiserror ourselves and make the same changes - with code gen of the Error trait disabled for no_std, so this isn't a question of it being a new crate or something, we're talking about the same crate in practical terms. I would have actually done that myself, but someone helpfully did it already, hence why I'm recommending we use it in the meantime.

I'm conservative about dependencies, more so than most I think, typically preferring to write something myself unless there are well established options that meet my other picky criteria, so I don't generally recommend a crate unless I believe it meets the bar for inclusion by a fair margin.

In any case, I didn't think the question was whether we should start using thiserror or not, but when. There isn't a good reason to wait for stabilization of error_in_core, dtolnay is doing so because it is easier for them to maintain the crate, i.e. they don't want to publish a temporary workaround like the linked fork. We don't have the same constraints, so it's really a matter of whether we can benefit from it before that happens, and that seems like a clear yes to me.

That said, I'd suggest waiting to see what my changes look like, and evaluate in that context, since we may not have any other stuff in the works that needs it just yet and this will provide some useful comparison.

@bobbinth
Copy link
Contributor

with code gen of the Error trait disabled for no_std, so this isn't a question of it being a new crate or something, we're talking about the same crate in practical terms.

Right - this is more of a general principal which I think is important specifically for crypto-related projects where supply-chain attacks are a very real risk. So, I try to keep the number of external dependencies to an absolute minimum and only use very well-known dependencies.

we can fork thiserror ourselves and make the same changes

We we do want to use this error, I would probably prefer this route. No need to do anything different for the PR you are working on, but we should probably follow it up with our own fork and then we can use it in all other repos as well.

@bobbinth
Copy link
Contributor

bobbinth commented Aug 7, 2024

Currently, we have our own forks of thiserror and miette dependencies which support no-std. Once relevant features in core get stabilized and these crates are updates to make use of them, we should move the dependencies to the canonical crates.

@bobbinth bobbinth added this to the v0.12 milestone Aug 7, 2024
@bitwalker
Copy link
Contributor

The 1.81 release looks like it will contain the stabilized error_in_core trait, and there is a draft PR in thiserror that implements the necessary changes there, but I'm not sure exactly how soon after 1.81 releases we can expect the thiserror release to drop, but probably pretty quickly afterwards, we can certainly update our fork to be the same changes so we're aligned with upstream.

For miette, we'll need to maintain a fork for awhile. I'm planning to spend some time reworking miden-diagnostics to basically take over the role of that dependency (by exporting a mostly-equivalent API, with the source management stuff integrated more natively into it, so we can move that out of miden-core). While miette is great for what it does, there are some aspects of it I don't like, and it isn't designed to be no-std compatible (I had to hack it in to our fork). The parts I do mostly like, are the rendering of diagnostics, the IntoDiagnostic, Diagnostic, and WrapErr traits, Report, and some of the conveniences like the diagnostic! and miette! macros - but I don't like any of the source management stuff it does, which is not well-suited to an environment where multiple sources are being worked on simultaneously (there is no way to tell the Report printer how to map a source span to a specific source file, it expects that you bind the relevant source file to the Report, but you can have diagnostics with spans in multiple files, and it is extremely awkward to handle this (I hacked together the RelatedLabel type to make this work, but it is not convenient to use).

Anyway, brain dumping this here for when we get to this, there isn't too much required to implement what I described above, so when I have some time to get to it, I'll do so.

@bobbinth
Copy link
Contributor

bobbinth commented Jan 8, 2025

Closed by #1588.

@bobbinth bobbinth closed this as completed Jan 8, 2025
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

No branches or pull requests

4 participants