poccariswet/apng

`errors` module is private

orhun opened this issue · 0 comments

orhun commented

Hi!

I'm trying to wrap APNGError in my application like this:

/* Custom error implementation */
#[derive(Debug, ThisError)]
pub enum AppError {
    // ...
    #[error("APNG error: `{0}`")]
    Apng(#[from] apng::errors::APNGError),
    // ...
}

But I get the following errors:

error[E0603]: module `errors` is private
  --> src/app.rs:51:21
   |
51 |     Apng(#[from] apng::errors::APNGError),
   |                        ^^^^^^ private module
   |
note: the module `errors` is defined here
  --> /home/orhun/.cargo/registry/src/github.com-1ecc6299db9ec823/apng-0.2.0/src/lib.rs:2:1
   |
2  | mod errors;
   | ^^^^^^^^^^^

error[E0599]: the method `as_dyn_error` exists for reference `&apng::errors::APNGError`, but its trait bounds were not satisfied
  --> src/app.rs:50:10
   |
50 |     #[error("APNG error: `{0}`")]
   |             ^^^^^^^^^^^^^^^^^^^ method cannot be called on `&apng::errors::APNGError` due to unsatisfied trait bounds
   | 
  ::: /home/orhun/.cargo/registry/src/github.com-1ecc6299db9ec823/apng-0.2.0/src/errors.rs:7:1
   |
7  | pub enum APNGError {
   | ------------------
   | |
   | doesn't satisfy `apng::errors::APNGError: AsDynError`
   | doesn't satisfy `apng::errors::APNGError: std::error::Error`
   |
   = note: the following trait bounds were not satisfied:
           `apng::errors::APNGError: std::error::Error`
           which is required by `apng::errors::APNGError: AsDynError`
           `&apng::errors::APNGError: std::error::Error`
           which is required by `&apng::errors::APNGError: AsDynError`

error: aborting due to 2 previous errors

First error is due to errors module being private. Applying the following diff solves the issue:

diff --git a/src/lib.rs b/src/lib.rs
index e0cb98b..ef3a84f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,5 @@
 mod apng;
-mod errors;
+pub mod errors;
 mod png;
 
 pub use crate::apng::*;

Second error is caused by the failure crate. It's fixed in #21

My question is: can we make errors module public? Or at least make APNGError public? I think it's important to expose these error types for use cases like mine.

What do you think? I'd like to provide a PR about this.