Skip to content

fix the error example to pass a constructor to fx.Provide#1290

Open
c-tonneslan wants to merge 1 commit into
uber-go:masterfrom
c-tonneslan:fix/error-example-provide-constructor
Open

fix the error example to pass a constructor to fx.Provide#1290
c-tonneslan wants to merge 1 commit into
uber-go:masterfrom
c-tonneslan:fix/error-example-provide-constructor

Conversation

@c-tonneslan

Copy link
Copy Markdown

Closes #1252.

The example's `fx.Provide` branch was passing a `*http.Server` value directly. `fx.Provide` expects a constructor function, so the moment `PORT` was set and that path actually ran, the app failed with "must provide constructor function." The doctest happened to still pass because it only exercised the PORT-unset branch.

Wrap the value in a closure so the second branch behaves as advertised the first time someone copies the snippet.

The example's fx.Provide branch was passing a *http.Server value
directly. fx.Provide expects a constructor function, so the moment
PORT was set and that path actually ran, the app failed with "must
provide constructor function." The example happened to still pass
its doctest because the doctest only exercised the PORT-unset
branch.

Wrap the value in a closure so the second branch behaves as advertised
the first time someone copies the snippet.

Closes uber-go#1252.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

error example does not work as expected

1 participant