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

break: return error from Customize request option #2267

Merged
merged 21 commits into from
Apr 26, 2024

Conversation

stevenh
Copy link
Collaborator

@stevenh stevenh commented Feb 25, 2024

What does this PR do?

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.

Closes #2266

BREAKING CHANGE: ContainerCustomizer.Customize now returns an error.

Why is it important?

Current implementation either hides errors in a log message or triggers a runtime panic, neither of which is ideal.

Related issues

Closes #2266

Copy link

netlify bot commented Feb 25, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 0e7cb73
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/662aa36db7d6b1000896ec8b
😎 Deploy Preview https://deploy-preview-2267--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@stevenh stevenh force-pushed the chore/options-error branch 3 times, most recently from 0a87c6f to 4c0c443 Compare February 25, 2024 20:49
@stevenh stevenh marked this pull request as ready for review February 25, 2024 20:53
@stevenh stevenh requested a review from a team as a code owner February 25, 2024 20:53
@stevenh stevenh marked this pull request as draft February 26, 2024 09:34
@stevenh
Copy link
Collaborator Author

stevenh commented Feb 26, 2024

Draft as I need to look at the failing tests, looks like the extra error checking is now making a bunch of them fail

modules/k3s/go.mod Outdated Show resolved Hide resolved
modules/weaviate/go.mod Outdated Show resolved Hide resolved
network/network.go Show resolved Hide resolved
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 testcontainers#2266

BREAKING CHANGE: `ContainerCustomizer.Customize` now returns an error.
Fix captured loop variable in mongodb test reported by govet.
Fix formatting in test file reported by gci during linting.
Add missing error returns for implementations of CustomizeRequestOption.
* main: (21 commits)
  feat: optimizes file copies to and from containers (testcontainers#2450)
  fix(exec): updates the `Multiplexed` opt to combine stdout and stderr (testcontainers#2452)
  Upgrade neo4j module to use features from v0.29.1 of testcontainers-go (testcontainers#2463)
  bug:Fix AMQPS url (testcontainers#2462)
  chore: more compose updates in comments
  chore: use "docker compose" (v2) instead of "docker-compose" (v1) (testcontainers#2464)
  chore(deps): bump github/codeql-action from 2.22.12 to 3.24.9 (testcontainers#2459)
  refactor: Add Weaviate modules tests (testcontainers#2447)
  feat(exitcode): Add exit code sugar method (testcontainers#2342)
  feat: add module to support InfluxDB v1.x (testcontainers#1703)
  feat: authenticate docker on PullImage (testcontainers#2446)
  feat: add distribution-registry module (testcontainers#2341)
  chore(deps): Bumping ChromaGo client version (testcontainers#2402)
  chore(deps): bump github.com/docker/docker from 25.0.3+incompatible to 25.0.5+incompatible (testcontainers#2444)
  feat: support passing io.Reader as ContainerFile (testcontainers#2401)
  chore: bump ryuk to latest (testcontainers#2395)
  feat(MustConn): Add MustConnectionString on (some) dbs (testcontainers#2343)
  fix: typo in ci-test-go.yml (testcontainers#2394)
  feat: support for waiting for response headers (testcontainers#2349)
  chore(deps): bump google.golang.org/protobuf from 1.32.0 to 1.33.0 (testcontainers#2392)
  ...
@mdelapenya
Copy link
Member

@stevenh If you agree I'm going to fetch this PR locally and start building on top of your code to make this into the next release. wdyt?

* main: (22 commits)
  feat: forward host ports to a container using an SSH tunnel (testcontainers#2471)
  Update follow_logs.md with adding missing package (testcontainers#2513)
  fix: don't retry on permanent APIClient errors (testcontainers#2506)
  feat: support overriding the default recreate options for compose (testcontainers#2511)
  feat: support passing io.Reader for compose files when creating a compose instance (testcontainers#2509)
  chore: add funding button for testcontainers (testcontainers#2510)
  feat: support Ryuk for the compose module (testcontainers#2485)
  chore(deps): bump golang.org/x/net in modules (minio, gcloud, weaviate, compose, qdrant, couchbase, k3s, milvus, mockserver, pulsar, kafka) (testcontainers#2505)
  fix: fallback to URL-path when parsing auth config URL without scheme (testcontainers#2488)
  fix(postgres): Fix the non-default dbname error (testcontainers#2489)
  feat: Bump default postgres version (testcontainers#2481)
  support Dolt (testcontainers#2177)
  chore: create TLS certs in a consistent manner (testcontainers#2478)
  chore(deps): bump idna from 3.6 to 3.7 (testcontainers#2480)
  Elasticsearch disable CA retrieval when ssl is disabled (testcontainers#2475)
  fix: handle dockerignore exclusions properly (testcontainers#2476)
  chore: prepare for next minor development cycle (0.31.0)
  chore: use new version (v0.30.0) in modules and examples
  Fix url creation to handle query params when using HTTP wait strategy (testcontainers#2466)
  fix: data race on container run (testcontainers#2345)
  ...
@stevenh
Copy link
Collaborator Author

stevenh commented Apr 24, 2024

@stevenh If you agree I'm going to fetch this PR locally and start building on top of your code to make this into the next release. wdyt?

Go for it!

@mdelapenya mdelapenya added the breaking change Causing compatibility issues. label Apr 25, 2024
@mdelapenya mdelapenya changed the title chore!: return error from Customize break: return error from Customize request option Apr 25, 2024
@mdelapenya mdelapenya self-assigned this Apr 25, 2024
@mdelapenya mdelapenya marked this pull request as ready for review April 25, 2024 11:26
Copy link
Collaborator Author

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can only comment, as my PR, but some small items to consider @mdelapenya

modules/neo4j/config.go Outdated Show resolved Hide resolved
port_forwarding.go Outdated Show resolved Hide resolved
port_forwarding.go Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@mdelapenya mdelapenya merged commit 14d6929 into testcontainers:main Apr 26, 2024
104 checks passed
@mdelapenya
Copy link
Member

Thank you @stevenh for bringing this issue to the table, and tackling it from the roots.

We introduced a breaking change for module creators, but I think it's worth it for the sake of a more robust API design.

I'll try to do great job in the release notes explaining it and proposing the upgrade path 🤞

@stevenh stevenh deleted the chore/options-error branch April 26, 2024 10:46
@stevenh
Copy link
Collaborator Author

stevenh commented Apr 26, 2024

Thanks for all your support @mdelapenya and finding the time to address the final issues with the PR, most appreciated!

mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Apr 26, 2024
* main: (34 commits)
  break: return error from Customize request option (testcontainers#2267)
  fix: wrong copy paste (testcontainers#2515)
  docs: add documentation for Exec method (testcontainers#2451)
  docs: document the SSHd tunnel (testcontainers#2514)
  fix: enhance host configuration port binding (testcontainers#2512)
  feat: forward host ports to a container using an SSH tunnel (testcontainers#2471)
  Update follow_logs.md with adding missing package (testcontainers#2513)
  fix: don't retry on permanent APIClient errors (testcontainers#2506)
  feat: support overriding the default recreate options for compose (testcontainers#2511)
  feat: support passing io.Reader for compose files when creating a compose instance (testcontainers#2509)
  chore: add funding button for testcontainers (testcontainers#2510)
  feat: support Ryuk for the compose module (testcontainers#2485)
  chore(deps): bump golang.org/x/net in modules (minio, gcloud, weaviate, compose, qdrant, couchbase, k3s, milvus, mockserver, pulsar, kafka) (testcontainers#2505)
  fix: fallback to URL-path when parsing auth config URL without scheme (testcontainers#2488)
  fix(postgres): Fix the non-default dbname error (testcontainers#2489)
  feat: Bump default postgres version (testcontainers#2481)
  support Dolt (testcontainers#2177)
  chore: create TLS certs in a consistent manner (testcontainers#2478)
  chore(deps): bump idna from 3.6 to 3.7 (testcontainers#2480)
  Elasticsearch disable CA retrieval when ssl is disabled (testcontainers#2475)
  ...
mdelapenya added a commit to khartld/testcontainers-go that referenced this pull request May 7, 2024
* main: (44 commits)
  feat: expose JSON representation of a container with Inspect (testcontainers#2534)
  chore(deps): bump test-summary action to v2.3 (testcontainers#2535)
  chore(deps): bump jinja2 from 3.1.3 to 3.1.4 (testcontainers#2533)
  Update devcontainer image (testcontainers#2531)
  chore(influxdb): include more characters in wait for log regex (testcontainers#2532)
  fix(compose): avoid race conditions when caching services (testcontainers#2528)
  chore(deps): bump golangci/golangci-lint-action from 3.7.0 to 5.1.0 (testcontainers#2525)
  chore(deps): bump mkdocs-material from 8.2.7 to 9.1.21 (testcontainers#2524)
  chore(compose): return error in options (testcontainers#2520)
  chore(deps): bump github.com/compose-spec/compose-go/v2 from v2.0.0-rc8 to v2.1.0 (testcontainers#2519)
  chore(deps): bump github.com/containerd/containerd from 1.7.12 to 1.7.15 (testcontainers#2517)
  break: return error from Customize request option (testcontainers#2267)
  fix: wrong copy paste (testcontainers#2515)
  docs: add documentation for Exec method (testcontainers#2451)
  docs: document the SSHd tunnel (testcontainers#2514)
  fix: enhance host configuration port binding (testcontainers#2512)
  feat: forward host ports to a container using an SSH tunnel (testcontainers#2471)
  Update follow_logs.md with adding missing package (testcontainers#2513)
  fix: don't retry on permanent APIClient errors (testcontainers#2506)
  feat: support overriding the default recreate options for compose (testcontainers#2511)
  ...
mdelapenya added a commit to mdelapenya/dynamodb-local-testcontainers-go that referenced this pull request Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Causing compatibility issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: support errors from container option
3 participants