-
Notifications
You must be signed in to change notification settings - Fork 139
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
RecycleError
has no purpose — is this intentional?
#266
Comments
You're 100% right. I was planning to add some more meaningful logs to the library but never came around to implement it. Discarding the Regarding the enum variants it boils down to this:
I was never very happy about that enum either but after a bunch of bikeshedding I just left it as is. Now that I think about this I guess a better approach would be to change this into a struct like that: /// This error type is returned by the [`Manager::recycle()`] method. Recycle errors
/// are never returned to the user of the library but are only used for logging and
/// possibly some advanced pool metrics in the future.
///
/// [`Manager::recycle()`]: super::Manager::recycle
#[derive(Debug)]
pub struct RecycleError {
/// An optional error message explaining the reason why the recycling failed.
pub message: Option<Cow<'static, str>>,
/// An optional cause for this error.
pub cause: Option<Box<dyn Error>>,
} The |
Thanks for the fast response, and the explanations — it’s a lot clearer now! The struct you posted would be good, I think, but it also is effectively the same as the The reason I think using an |
Using the It's a micro optimization and I might be overthinking this a lot. Recycle errors are supposed to happen rarely and if those are ever going to be a problem you got some other issues to deal with anyways. |
I moved this issue to the 0.10 Milestone as I want to tackle all API breaking changes in the next release. I'm a bit undecided if I |
One advantage of using an |
I moved that to the 0.11 Milestone as I want to get 0.10 out of the door. Right now it's merely cosmetic and should not block the 0.10 release. |
I was always mystified by the algorithm used by
managed::Pool
to determine what happens when recycling fails, since it’s not documented. If one checks the definition of theManager
trait they will see that therecycle
method takes a unique reference to an object and gives aRecycleResult<Self::Error>
, whereRecycleError
is:The docs contain no information that helps here, so I’m left to question: Why? And after lots of reasoning and reading the docs, there is only one conclusion I could come to: It doesn’t make any sense at all. Let’s look at the thought process.
The
recycle
method chooses to give aRecycleResult<Self::Error>
instead of aResult<(), Self::Error>
. If we check the docs ofManager::Error
, we see:However, if we check the docs of
RecycleError::Message
, we see:So, we can logically conclude that we should return
RecycleError::Message
in cases where:Manager::Error
was returned)RecycleError::Message
was returnedThis is not a situation that can ever happen, as it’s directly contradictory, so we can logically conclude that
RecycleError::Message
(andStaticMessage
) should never be returned. In that case, why have it, why is this a feature of the library?Okay, well under the assumption that the library’s design makes sense, maybe I misread “some other reason” and it in fact “other reason” did not refer to recycling failing, but rather referred to something else. The other enum variant available is called “backend”, and says it is for an “Error caused by the backend”. “Backend” isn’t a well-defined term in this context, so we have to guess what it means. Well, we know that:
create
can only fail because of the backend;recycle
can fail because of the backend, or because something else happened.What does
recycle
do more thancreate
that means it can fail in ways not caused by the backend? Well, it depends on the implementation. But at its face value, the proposition makes no sense: given that the error type ofcreate
isSelf::Error
it is most logical to assume that a backend error represents the creation of the resource failing. But the implementation ofrecycle
quite explicitly should not be creating resources, so for what reason would the backend fail in it anyway?Maybe “backend” represents any interaction with whatever entity is providing the resources; but then why is it assumed that, in the general case,
recycle
does more than just that interaction thancreate
does? Why wouldn’t we also have aCreateError
if we wished to enforce this “backend” model upon implementations ofManager
?So clearly this route is not the correct one. Let’s take an alternate angle: maybe the library is (internally and opaquely, because this is definitely not documented) making use of the structural details provided by the
RecycleError
enum somehow, so it’s matching on theenum
and deciding what control flow path to take. If we check the current source code however, we’ll see that it doesn’t do this in.get()
, in fact it does this nowhere in the library, nor is that structural information ever bubbled up to the user — the entireRecycleError
is fully discarded without logging. This means the only logical conclusion is that the library is planning on using this information in a future version, it’s just not implemented.There don’t seem to be any comments or issues that hint to that though, so I’m guessing it’s some secret plan of the maintainer — the only problem is that I don’t know how I can best prepare for that change when it comes around, because as seen above the docs of
RecycleError
are too sparse to know which error I should be giving in what scenario.At this point, I gave up and chose to file this issue. I really cannot conceptualize what this type is and what it’s used for, and so I don’t know how to correctly use the library.
If the intention of the library author is that it is an API stability guarantee that
RecycleError
s are ignored, I would suggest we use an alternative design to make this more explicit:The fact that
RecycleError
is a unit struct makes it very explicit to the user that the library does not care what information it contains, and will simply ignore all data inside it. The user is encouraged to log errors if they care about them, or drop them if they don’t.If the intention of the library author is for
RecycleError::Message
to have legitimately different semantic meaning fromRecycleError::Backend
, it would be very helpful to document this, and I would be willing to submit a PR for that if explained to me.If the intention of the library author is to eventually introduce logging or something similar so that recycling errors aren’t fully ignored, I would suggest the following design for
Manager
instead:This gives more flexibility on the part of the implementor of
Manager
to use whichever error type is most conveniënt for them.The text was updated successfully, but these errors were encountered: