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

Concrete errors for library APIs #4407

Open
musjj opened this issue Feb 23, 2025 · 1 comment
Open

Concrete errors for library APIs #4407

musjj opened this issue Feb 23, 2025 · 1 comment

Comments

@musjj
Copy link

musjj commented Feb 23, 2025

This library makes very frequent use of anyhow::Result, especially for its public APIs. This is usually considered bad practice because it makes error handling impossible.

Like for example, with TopicProducer::send it's impossible to tell why it fails. Maybe the topic didn't exist, maybe there was a connection issue, there's just no way to know because it returns an opaque error type.

There's already a concrete error enum here:

pub enum FluvioError {
#[error(transparent)]
Io(#[from] IoError),
#[error("Topic not found: {0}")]
TopicNotFound(String),
#[error("Partition not found: {0}-{1}")]
PartitionNotFound(String, PartitionId),

Is there a reason why it's not used more often throughout the library? Concrete errors would make our lives SO much easier!

@sehz
Copy link
Contributor

sehz commented Feb 23, 2025

You can use downcast to match for specific error like here:

match err.downcast_ref::<PackageNotFound>() {
                Some(PackageNotFound {
                    package,

We used have concrete error type. Fluvio has lots of moving parts building distributed system. Errors can come from any source (network, disk, etc). With concrete error type, you have to continuously remap underlying error which takes lots of efforts to maintain. So many fluvio errors are actually application error type.

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

2 participants