-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
[Enhancement]: support errors from container option #2266
Comments
I like the idea @stevenh, in fact I've thinking a few times how to deal with that but always without enough bandwidth to do a deep research, thanks for coming with your ideas. If they community likes it, I support it as a "breaking change" for the current in-development version, but as part of the public API for an eventual v1. |
Thanks @mdelapenya, to confirm you're happy to just make the |
I had an hour, so went ahead with what I assumed from your comment #2267 is now up for review. Wasn't sure if there was some where else this type of change should be documented, but put it on the options page. |
Hey @stevenh I've been thinking about this today more in depth. I think any option should do one of these two things: configure the container request, or add code to be executed honouring the container lifecycle hooks. The first one, defining the container request, in the worst case scenario, could lead to an inconsistent state, and that should be captured by the RunContainer function because the container won't be able to start. The most flagrant use case would be passing an image that does not exist: The second one, leveraging the container lifecycle hooks: they add functions that already return error and are handled by the container lifecycle, so it should cover any kind of validation you want to do in the container for each event (pre/post create/stop/start/ready/stop), signalling the caller about that in the RunContainer function too, and possibly adding custom error messages for it. Is that the case you want to see that validation support in the functional options for the containers/modules? If that's the case, I think it's responsibility of the caller to pass the right values and not from the library. I think I have to step back in my previous comment, and at least start the discussion from this point. Sorry if I put you to work before having these thoughts 🙏 |
While most options for configuring the request will be error free, there are definitely cases that can and in fact already do trigger an error. These errors need to be returned early as they are preventing the request being configured as requested. This isn't something that would be covered by the lifecycle management if that's what you were thinking? |
Some examples of failures that are currently hidden or result in a panic are WithNewNetwork and Neo4j, Clickhouse options. Given Customize is the only way consumers can mutate the request before it's sent when using RunContainer of modules we can't assume that those mutations will be error free as it depends entirely on the use case which we can't predict. Hope that clarifies why options need to be able to handle errors? |
I think we are going to work on this, thanks for bringing the topic to the table. I see it more and more that it needed, so thank you again for convincing me :) We need a solid plan for communicating the breaking changes: in the docs, in the public APIs, and in the community (probably on Slack) I'd appreciate your help in this mini-project 😅 |
Thanks @mdelapenya happy to help, see you have some comments on the draft PR already. Where would you like to centralise the conversation about the implementation, should that be here or on a PR? |
I think the PR is fine, so we are closer to the code. |
* chore!: return error from Customize Change ContainerCustomizer.Customize method to return an error so that options can handle errors gracefully instead of relying on panic or just a log entry, neither of which are user friendly. Enable errcheck linter to ensure that errors that aren't handled are reported. Run go mod tidy on k3s and weaviate to allow tests to be run using go 1.22. Run gofumpt on a few files to satisfy golangci-lint. Fix direct comparison with http.ErrServerClosed flagged by errcheck. Fixes #2266 BREAKING CHANGE: `ContainerCustomizer.Customize` now returns an error. * fix(mongodb): captured loop variable Fix captured loop variable in mongodb test reported by govet. * fix(k3s): test formatting Fix formatting in test file reported by gci during linting. * chore: add missing Customize error returns Add missing error returns for implementations of CustomizeRequestOption. * chore: update modules with the new error API * fix: use logger * fix: update modulegen tests * chore: fix lint * chore: handle customise errors * chore: update new host port access option * docs: move new error API to the right doc * docs: move customise request to the bottom * docs: sync functional options * chore: avoid panics in localstack * chore: require no error in test * chore: ignore error in copy API, using nolint:errcheck * chore: convert log into error --------- Co-authored-by: Manuel de la Peña <[email protected]>
Proposal
The current version of
ContainerCustomizer
provides the ability to customise a container in setup but as doesn't return an error so methods which do need to handle errors either have to panic or just the log the error and hope the user checks the log file, neither of which is a good user experience.I propose we introduce a new type and interface that allows consumers to gracefully upgrade to a flow which will allow handling of errors from container customisation.
For example:
This will allow options which can encounter an error to switch from returning a
ContainerOption
toSafeContainerOption
in a way which is compatible.Handlers would need to check if the type implements
SafeContainerOption
and use it in preference for example:We could change the
ContainerCustomizer
, giventestcontainers
is still pre v1,but not a nice user experience, but it should be removed in v2 in my opinion.Thoughts?
Happy to do implement if folks agree.
The text was updated successfully, but these errors were encountered: