-
Notifications
You must be signed in to change notification settings - Fork 142
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
RFC: add fallible result-based API #606
Comments
I'd say we should let the users decide whether they want to handle errors or not. WDYT? We might need to find a way to be able to do that API change gracefully with deprecations though. |
That was just a proposal to start with Graceful switch is a bit complicated if we want to preserve method names, however I see several ways to do that, mostly by using wrappers, like: I can provide more examples a bit later, but that's definitely possible. However I'm not totally sure if we really need to be crazy about compatibility, because it's anyway breaking change at the end. Probably, good migration guide is enough. After some major changes we can release version |
That sounds about right now that I think about it again. |
Closes #606 ## Migration guide - The easiest way to use `unwrap` or `expect` for all `testcontainers` operations. - or you can cast error if your tests are already `Result` based (for `anyhow::Result` it's enough to use `?`) - The `Image::exec_after_start` method returns a `Result`, so if you have an implementation of `Image` that uses `exec_after_start`, it's important to handle possible errors.
Closes #606 ## Migration guide - The easiest way to use `unwrap` or `expect` for all `testcontainers` operations. - or you can cast error if your tests are already `Result` based - The `Image::exec_after_start` method returns a `Result`, so if you have an implementation of `Image` that uses `exec_after_start`, it's important to handle possible errors (e.g required port not found)
At the moment,
testcontainers
panics in case of any error.It makes it easier to use, but complicates the flexibility of the code and the ability to customize errors.
I suggest refactoring this and returning meaningful errors. This greatly expands the possibilities of use.
We can preserve panicking API by using a common pattern: providing fallible methods with a
try_
prefix and keep existing ones as delegates that unwraps theResult
.For example:
The text was updated successfully, but these errors were encountered: