Repository: favonia/cloudflare-ddns
Pull request #846 (2024-07-27 20:22:15)

refactor: use ppfmt.Warningf more

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/846?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 93.99%. Comparing base [(`17d2d32`)](https://app.codecov.io/gh/favonia/cloudflare-ddns/commit/17d2d327d47f10596c4f48a131768c414d0e1a5d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) to head [(`a586b36`)](https://app.codecov.io/gh/favonia/cloudflare-ddns/commit/a586b3681e2746fe7dee28d6f3d8d2de173899eb?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #846   +/-   ##
=======================================
  Coverage   93.99%   93.99%           
=======================================
  Files          54       54           
  Lines        2198     2198           
=======================================
  Hits         2066     2066           
  Misses        120      120           
  Partials       12       12           
```

| [Flag](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/846/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) | Coverage Δ | |
|---|---|---|
| [unittests](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/846/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) | `93.99% <100.00%> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia#carryforward-flags-in-the-pull-request-comment) to find out more.

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/846?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia).


Patch:
diff --git a/internal/notifier/shoutrrr.go b/internal/notifier/shoutrrr.go
index ae40f9e..89ef849 100644
--- a/internal/notifier/shoutrrr.go
+++ b/internal/notifier/shoutrrr.go
@@ -59,7 +59,7 @@ func (s Shoutrrr) Send(_ context.Context, ppfmt pp.PP, msg string) bool {
 	allOk := true
 	for _, err := range errs {
 		if err != nil {
-			ppfmt.Errorf(pp.EmojiError, "Failed to send shoutrrr message: %v", err)
+			ppfmt.Warningf(pp.EmojiError, "Failed to send shoutrrr message: %v", err)
 			allOk = false
 		}
 	}
diff --git a/internal/pp/verbosity.go b/internal/pp/verbosity.go
index e159757..af11e5c 100644
--- a/internal/pp/verbosity.go
+++ b/internal/pp/verbosity.go
@@ -8,7 +8,7 @@ const (
 	Debug            Verbosity = iota // debugging info (currently not used)
 	Info                              // additional information that is not an action, a warning, or an error
 	Notice                            // an action (e.g., changing the IP) that is not an error
-	Warning                           // non-fatal errors where we should continue updating IP addresses
+	Warning                           // non-fatal errors where the updater should continue
 	Error                             // fatal errors where the updater should stop
 	Verbose          Verbosity = Info
 	Quiet            Verbosity = Notice
diff --git a/internal/provider/protocol/doh.go b/internal/provider/protocol/doh.go
index fdf04b6..5f3812e 100644
--- a/internal/provider/protocol/doh.go
+++ b/internal/provider/protocol/doh.go
@@ -96,7 +96,7 @@ func parseDNSAnswers(ppfmt pp.PP, answers []dnsmessage.Resource,
 
 	ip, err := netip.ParseAddr(ipString)
 	if err != nil {
-		ppfmt.Errorf(
+		ppfmt.Warningf(
 			pp.EmojiImpossible,
 			`Invalid DNS response: failed to parse the IP address in the TXT record: %s`,
 			ipString,
diff --git a/internal/provider/protocol/http.go b/internal/provider/protocol/http.go
index 090ddad..4c1703b 100644
--- a/internal/provider/protocol/http.go
+++ b/internal/provider/protocol/http.go
@@ -20,7 +20,7 @@ func getIPFromHTTP(ctx context.Context, ppfmt pp.PP, url string) (netip.Addr, bo
 			ipString := strings.TrimSpace(string(body))
 			ip, err := netip.ParseAddr(ipString)
 			if err != nil {
-				ppfmt.Errorf(pp.EmojiImpossible, `Failed to parse the IP address in the response of %q: %s`, url, ipString)
+				ppfmt.Warningf(pp.EmojiImpossible, `Failed to parse the IP address in the response of %q: %s`, url, ipString)
 				return netip.Addr{}, false
 			}
 			return ip, true
diff --git a/internal/setter/setter.go b/internal/setter/setter.go
index 3a14348..42737ed 100644
--- a/internal/setter/setter.go
+++ b/internal/setter/setter.go
@@ -193,7 +193,7 @@ func (s setter) Set(ctx context.Context, ppfmt pp.PP,
 
 	// Check whether we are done. It is okay to have duplicates, but it is not okay to have remaining stale records.
 	if !foundMatched || numUndeletedUnmatched > 0 {
-		ppfmt.Errorf(pp.EmojiError,
+		ppfmt.Warningf(pp.EmojiError,
 			"Failed to finish updating %s records of %q; records might be inconsistent",
 			recordType, domainDescription)
 		return ResponseFailed
@@ -247,7 +247,7 @@ func (s setter) Delete(ctx context.Context, ppfmt pp.PP, domain domain.Domain, i
 		ppfmt.Noticef(pp.EmojiDeletion, "Deleted a stale %s record of %q (ID: %q)", recordType, domainDescription, id)
 	}
 	if !allOk {
-		ppfmt.Errorf(pp.EmojiError,
+		ppfmt.Warningf(pp.EmojiError,
 			"Failed to finish deleting %s records of %q; records might be inconsistent",
 			recordType, domainDescription)
 		return ResponseFailed
diff --git a/internal/updater/updater.go b/internal/updater/updater.go
index 3009930..9b69994 100644
--- a/internal/updater/updater.go
+++ b/internal/updater/updater.go
@@ -55,7 +55,7 @@ func detectIP(ctx context.Context, ppfmt pp.PP,
 	if ok {
 		ppfmt.Infof(pp.EmojiInternet, "Detected the %s address: %v", ipNet.Describe(), ip)
 	} else {
-		ppfmt.Errorf(pp.EmojiError, "Failed to detect the %s address", ipNet.Describe())
+		ppfmt.Warningf(pp.EmojiError, "Failed to detect the %s address", ipNet.Describe())
 
 		if ShouldDisplayHints[HintDetectionTimeouts] && errors.Is(context.Cause(ctx), errTimeout) {
 			ppfmt.Infof(pp.EmojiHint,


Test patch:
diff --git a/internal/notifier/shoutrrr_test.go b/internal/notifier/shoutrrr_test.go
index c4b773e..418465f 100644
--- a/internal/notifier/shoutrrr_test.go
+++ b/internal/notifier/shoutrrr_test.go
@@ -54,7 +54,7 @@ func TestShoutrrrSend(t *testing.T) {
 			"hello",
 			false, false,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Errorf(pp.EmojiError, "Failed to send shoutrrr message: %v", gomock.Any())
+				m.EXPECT().Warningf(pp.EmojiError, "Failed to send shoutrrr message: %v", gomock.Any())
 			},
 		},
 	} {
diff --git a/internal/provider/protocol/doh_test.go b/internal/provider/protocol/doh_test.go
index 6f54883..7661e26 100644
--- a/internal/provider/protocol/doh_test.go
+++ b/internal/provider/protocol/doh_test.go
@@ -458,7 +458,7 @@ func TestDNSOverHTTPSGetIP(t *testing.T) {
 			},
 			invalidIP,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Errorf(
+				m.EXPECT().Warningf(
 					pp.EmojiImpossible,
 					`Invalid DNS response: failed to parse the IP address in the TXT record: %s`,
 					"I am definitely not an IP address",
diff --git a/internal/provider/protocol/http_test.go b/internal/provider/protocol/http_test.go
index 4895575..d2eacd0 100644
--- a/internal/provider/protocol/http_test.go
+++ b/internal/provider/protocol/http_test.go
@@ -84,7 +84,7 @@ func TestHTTPGetIP(t *testing.T) {
 			"4-nil1": {
 				false, ipnet.IP4, dummy.URL, ipnet.IP4, invalidIP,
 				func(m *mocks.MockPP) {
-					m.EXPECT().Errorf(
+					m.EXPECT().Warningf(
 						pp.EmojiImpossible,
 						`Failed to parse the IP address in the response of %q: %s`,
 						dummy.URL,
@@ -94,7 +94,7 @@ func TestHTTPGetIP(t *testing.T) {
 			"6-nil1": {
 				false, ipnet.IP6, dummy.URL, ipnet.IP6, invalidIP,
 				func(m *mocks.MockPP) {
-					m.EXPECT().Errorf(
+					m.EXPECT().Warningf(
 						pp.EmojiImpossible,
 						`Failed to parse the IP address in the response of %q: %s`,
 						dummy.URL,
diff --git a/internal/setter/setter_test.go b/internal/setter/setter_test.go
index 9e73c20..2f06e06 100644
--- a/internal/setter/setter_test.go
+++ b/internal/setter/setter_test.go
@@ -320,8 +320,8 @@ func TestSet(t *testing.T) {
 					h.EXPECT().DeleteRecord(ctx, p, domain, ipNetwork, record2).Return(true),
 					p.EXPECT().Noticef(pp.EmojiDeletion, "Deleted a stale %s record of %q (ID: %q)", "AAAA", "sub.test.org", record2), //nolint:lll
 					h.EXPECT().CreateRecord(ctx, p, domain, ipNetwork, ip1, api.TTLAuto, false, "hello").Return(record3, true),
-					p.EXPECT().Noticef(pp.EmojiCreation, "Added a new %s record of %q (ID: %q)", "AAAA", "sub.test.org", record3),                         //nolint:lll
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to finish updating %s records of %q; records might be inconsistent", "AAAA", "sub.test.org"), //nolint:lll
+					p.EXPECT().Noticef(pp.EmojiCreation, "Added a new %s record of %q (ID: %q)", "AAAA", "sub.test.org", record3),                           //nolint:lll
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to finish updating %s records of %q; records might be inconsistent", "AAAA", "sub.test.org"), //nolint:lll
 				)
 			},
 		},
@@ -338,7 +338,7 @@ func TestSet(t *testing.T) {
 					h.EXPECT().DeleteRecord(ctx, p, domain, ipNetwork, record2).Return(true),
 					p.EXPECT().Noticef(pp.EmojiDeletion, "Deleted a stale %s record of %q (ID: %q)", "AAAA", "sub.test.org", record2), //nolint:lll
 					h.EXPECT().CreateRecord(ctx, p, domain, ipNetwork, ip1, api.TTLAuto, false, "hello").Return(record3, false),
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to finish updating %s records of %q; records might be inconsistent", "AAAA", "sub.test.org"), //nolint:lll
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to finish updating %s records of %q; records might be inconsistent", "AAAA", "sub.test.org"), //nolint:lll
 				)
 			},
 		},
@@ -445,7 +445,7 @@ func TestDelete(t *testing.T) {
 				gomock.InOrder(
 					h.EXPECT().ListRecords(ctx, p, domain, ipNetwork).Return(map[string]netip.Addr{record1: ip1}, true, true),
 					h.EXPECT().DeleteRecord(ctx, p, domain, ipNetwork, record1).Return(false),
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to finish deleting %s records of %q; records might be inconsistent", "AAAA", "sub.test.org"), //nolint:lll
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to finish deleting %s records of %q; records might be inconsistent", "AAAA", "sub.test.org"), //nolint:lll
 				)
 			},
 		},
diff --git a/internal/updater/updater_test.go b/internal/updater/updater_test.go
index be4ab8a..a593baa 100644
--- a/internal/updater/updater_test.go
+++ b/internal/updater/updater_test.go
@@ -320,7 +320,7 @@ func TestUpdateIPsHints(t *testing.T) {
 					s.EXPECT().Set(gomock.Any(), p, domain.FQDN("ip4.hello"), ipnet.IP4, ip4, api.TTLAuto, false, RecordComment).
 						Return(setter.ResponseNoop),
 					pv[ipnet.IP6].EXPECT().GetIP(gomock.Any(), p, ipnet.IP6, true).Return(netip.Addr{}, false),
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to detect the %s address", "IPv6"),
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to detect the %s address", "IPv6"),
 				)
 			},
 		},
@@ -495,7 +495,7 @@ func TestUpdateIPs(t *testing.T) {
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) {
 				gomock.InOrder(
 					pv[ipnet.IP4].EXPECT().GetIP(gomock.Any(), p, ipnet.IP4, true).Return(netip.Addr{}, false),
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to detect the %s address", "IPv4"),
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to detect the %s address", "IPv4"),
 					p.EXPECT().Infof(pp.EmojiHint, "If your network does not support IPv4, you can disable it with IP4_PROVIDER=none"), //nolint:lll
 					pv[ipnet.IP6].EXPECT().GetIP(gomock.Any(), p, ipnet.IP6, true).Return(ip6, true),
 					p.EXPECT().Infof(pp.EmojiInternet, "Detected the %s address: %v", "IPv6", ip6),
@@ -516,7 +516,7 @@ func TestUpdateIPs(t *testing.T) {
 					s.EXPECT().Set(gomock.Any(), p, domain.FQDN("ip4.hello"), ipnet.IP4, ip4, api.TTLAuto, false, RecordComment).
 						Return(setter.ResponseNoop),
 					pv[ipnet.IP6].EXPECT().GetIP(gomock.Any(), p, ipnet.IP6, true).Return(netip.Addr{}, false),
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to detect the %s address", "IPv6"),
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to detect the %s address", "IPv6"),
 					p.EXPECT().Infof(pp.EmojiHint, "If you are using Docker or Kubernetes, IPv6 often requires additional setups"),     //nolint:lll
 					p.EXPECT().Infof(pp.EmojiHint, "Read more about IPv6 networks at https://github.com/favonia/cloudflare-ddns"),      //nolint:lll
 					p.EXPECT().Infof(pp.EmojiHint, "If your network does not support IPv6, you can disable it with IP6_PROVIDER=none"), //nolint:lll
@@ -531,10 +531,10 @@ func TestUpdateIPs(t *testing.T) {
 			func(p *mocks.MockPP, pv mockProviders, _ *mocks.MockSetter) {
 				gomock.InOrder(
 					pv[ipnet.IP4].EXPECT().GetIP(gomock.Any(), p, ipnet.IP4, true).Return(netip.Addr{}, false),
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to detect the %s address", "IPv4"),
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to detect the %s address", "IPv4"),
 					p.EXPECT().Infof(pp.EmojiHint, "If your network does not support IPv4, you can disable it with IP4_PROVIDER=none"), //nolint:lll
 					pv[ipnet.IP6].EXPECT().GetIP(gomock.Any(), p, ipnet.IP6, true).Return(netip.Addr{}, false),
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to detect the %s address", "IPv6"),
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to detect the %s address", "IPv6"),
 					p.EXPECT().Infof(pp.EmojiHint, "If you are using Docker or Kubernetes, IPv6 often requires additional setups"),     //nolint:lll
 					p.EXPECT().Infof(pp.EmojiHint, "Read more about IPv6 networks at https://github.com/favonia/cloudflare-ddns"),      //nolint:lll
 					p.EXPECT().Infof(pp.EmojiHint, "If your network does not support IPv6, you can disable it with IP6_PROVIDER=none"), //nolint:lll
@@ -555,7 +555,7 @@ func TestUpdateIPs(t *testing.T) {
 								return netip.Addr{}, false
 							},
 						),
-					p.EXPECT().Errorf(pp.EmojiError, "Failed to detect the %s address", "IPv4"),
+					p.EXPECT().Warningf(pp.EmojiError, "Failed to detect the %s address", "IPv4"),
 					p.EXPECT().Infof(pp.EmojiHint, "If your network is experiencing high latency, consider increasing DETECTION_TIMEOUT=%v", time.Second), //nolint:lll
 				)
 			},