argmin-rs / argmin

Numerical optimization in pure Rust
http://argmin-rs.org
Apache License 2.0
1k stars 79 forks source link

Implement better Error types #507

Open DevonMorris opened 2 months ago

DevonMorris commented 2 months ago

Generally, it's frowned upon to have type-erased error types in library code.

Specifically, in your library, you've defined Solver::next_iter with an anyhow::Error as the error type. This means that even if I implement Solver on one of my own types and I've defined a custom error type, I'll have to to type erase that error type using anyhow and then try to dynamically downcast to get error-specific information out.

I propose that we refactor Solver to be generic over error types and that we implement custom error types for the solvers that currently exist.

A crate that would make this transition much easier is thiserror and we can additionally add miette for better diagnostics.

stefan-k commented 2 months ago

This is something I haven't been happy with for a while and therefore I'm all for changing it as you proposed. Unfortunately the time I can invest in this is currently very limited. Would you be able to provide a PR?

DevonMorris commented 2 months ago

I'll try to find some time in the evenings soon and work on this. Might be a couple of weeks before I get it wrapped, however.

DevonMorris commented 1 month ago

Just an update, I took a first pass at this, but haven't gotten through the entire refactor. Work has ramped up again in the last little bit so I've found myself lacking time in the evenings.

All this to say, I haven't forgotten about this things have just been busy. Hopefully, I'll be able to make some time soon.