Repository: uber-go/fx
Pull request #981 (2022-10-27 17:44:33)

Log Supply errors at error level for Zap logger
Currently the Supplied event is not being logged at Error level even when there is an error encountered while supplying.

This fixes that.

codecov[bot]: # [Codecov](https://codecov.io/gh/uber-go/fx/pull/981?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) Report
> Merging [#981](https://codecov.io/gh/uber-go/fx/pull/981?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) (2e079d7) into [master](https://codecov.io/gh/uber-go/fx/commit/bd8f9611824480f5ae136341c843c6607e1dbe08?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) (bd8f961) will **increase** coverage by `0.16%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master     #981      +/-   ##
==========================================
+ Coverage   98.62%   98.79%   +0.16%     
==========================================
  Files          38       32       -6     
  Lines        1529     1488      -41     
==========================================
- Hits         1508     1470      -38     
+ Misses         15       13       -2     
+ Partials        6        5       -1     
```


| [Impacted Files](https://codecov.io/gh/uber-go/fx/pull/981?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) | Coverage Δ | |
|---|---|---|
| [fxevent/zap.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZnhldmVudC96YXAuZ28=) | `100.00% <100.00%> (ø)` | |
| [lifecycle.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-bGlmZWN5Y2xlLmdv) | `100.00% <0.00%> (ø)` | |
| [internal/lifecycle/lifecycle.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-aW50ZXJuYWwvbGlmZWN5Y2xlL2xpZmVjeWNsZS5nbw==) | `100.00% <0.00%> (ø)` | |
| [docs/internal/exectest/output.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZG9jcy9pbnRlcm5hbC9leGVjdGVzdC9vdXRwdXQuZ28=) | | |
| [docs/internal/httptest/http.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZG9jcy9pbnRlcm5hbC9odHRwdGVzdC9odHRwLmdv) | | |
| [docs/internal/apptest/run.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZG9jcy9pbnRlcm5hbC9hcHB0ZXN0L3J1bi5nbw==) | | |
| [docs/internal/exectest/cmd.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZG9jcy9pbnRlcm5hbC9leGVjdGVzdC9jbWQuZ28=) | | |
| [docs/internal/test/fake.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZG9jcy9pbnRlcm5hbC90ZXN0L2Zha2UuZ28=) | | |
| [docs/internal/iotest/read.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZG9jcy9pbnRlcm5hbC9pb3Rlc3QvcmVhZC5nbw==) | | |
| [annotated.go](https://codecov.io/gh/uber-go/fx/pull/981/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-YW5ub3RhdGVkLmdv) | `99.69% <0.00%> (+<0.01%)` | :arrow_up: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go)


Patch:
diff --git a/fxevent/zap.go b/fxevent/zap.go
index 320dec9..9fb7e47 100644
--- a/fxevent/zap.go
+++ b/fxevent/zap.go
@@ -75,10 +75,17 @@ func (l *ZapLogger) LogEvent(event Event) {
 			)
 		}
 	case *Supplied:
-		l.Logger.Info("supplied",
-			zap.String("type", e.TypeName),
-			moduleField(e.ModuleName),
-			zap.Error(e.Err))
+		if e.Err != nil {
+			l.Logger.Error("error encountered while applying options",
+				zap.String("type", e.TypeName),
+				moduleField(e.ModuleName),
+				zap.Error(e.Err))
+		} else {
+			l.Logger.Info("supplied",
+				zap.String("type", e.TypeName),
+				moduleField(e.ModuleName),
+			)
+		}
 	case *Provided:
 		for _, rtype := range e.OutputTypeNames {
 			l.Logger.Info("provided",


Test patch:
diff --git a/fxevent/zap_test.go b/fxevent/zap_test.go
index 6689535..b25358d 100644
--- a/fxevent/zap_test.go
+++ b/fxevent/zap_test.go
@@ -137,7 +137,7 @@ func TestZapLogger(t *testing.T) {
 		{
 			name:        "SuppliedError",
 			give:        &Supplied{TypeName: "*bytes.Buffer", Err: someError},
-			wantMessage: "supplied",
+			wantMessage: "error encountered while applying options",
 			wantFields: map[string]interface{}{
 				"type":  "*bytes.Buffer",
 				"error": "some error",