Repository: favonia/cloudflare-ddns
Pull request #986 (2024-11-20 13:35:30)

fix(protocol): quote unknown strings in logging

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/986?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 95.08%. Comparing base [(`73a4ba3`)](https://app.codecov.io/gh/favonia/cloudflare-ddns/commit/73a4ba32727eee195fb36787744c371b799a4e7b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) to head [(`7e30fa6`)](https://app.codecov.io/gh/favonia/cloudflare-ddns/commit/7e30fa6be304c701615774ea2332f3f3b219e7ff?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     #986   +/-   ##
=======================================
  Coverage   95.08%   95.08%           
=======================================
  Files          64       64           
  Lines        3457     3457           
=======================================
  Hits         3287     3287           
  Misses        158      158           
  Partials       12       12           
```

| [Flag](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/986/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/986/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) | `95.08% <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/986?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).

----
🚨 Try these New Features:

- [Flaky Tests Detection](https://docs.codecov.com/docs/test-result-ingestion-beta) - Detect and resolve failed and flaky tests

Patch:
diff --git a/internal/provider/protocol/http.go b/internal/provider/protocol/http.go
index 5a1c688..79b9f32 100644
--- a/internal/provider/protocol/http.go
+++ b/internal/provider/protocol/http.go
@@ -21,7 +21,7 @@ func getIPFromHTTP(ctx context.Context, ppfmt pp.PP, ipNet ipnet.Type, url strin
 			ipString := strings.TrimSpace(string(body))
 			ip, err := netip.ParseAddr(ipString)
 			if err != nil {
-				ppfmt.Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q: %s`, url, ipString)
+				ppfmt.Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q (%q)`, url, ipString)
 				return netip.Addr{}, false
 			}
 			return ip, true
diff --git a/internal/provider/protocol/regexp.go b/internal/provider/protocol/regexp.go
index 589fca6..94afc78 100644
--- a/internal/provider/protocol/regexp.go
+++ b/internal/provider/protocol/regexp.go
@@ -23,13 +23,13 @@ func getIPFromRegexp(ctx context.Context, ppfmt pp.PP, ipNet ipnet.Type, url str
 
 			matched := re.FindSubmatch(body)
 			if len(matched) < 2 {
-				ppfmt.Noticef(pp.EmojiError, `Failed to find the IP address in the response of %q: %s`, url, body)
+				ppfmt.Noticef(pp.EmojiError, `Failed to find the IP address in the response of %q (%q)`, url, body)
 				return invalidIP, false
 			}
 			ipString := string(matched[1])
 			ip, err := netip.ParseAddr(ipString)
 			if err != nil {
-				ppfmt.Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q: %s`, url, ipString)
+				ppfmt.Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q (%q)`, url, ipString)
 				return invalidIP, false
 			}
 			return ip, true


Test patch:
diff --git a/internal/provider/protocol/http_test.go b/internal/provider/protocol/http_test.go
index 6e47bb9..3f2f4d1 100644
--- a/internal/provider/protocol/http_test.go
+++ b/internal/provider/protocol/http_test.go
@@ -93,14 +93,14 @@ func TestHTTPGetIP(t *testing.T) {
 			false,
 			ipnet.IP4, illformed4.URL, ipnet.IP4, invalidIP,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q: %s`, illformed4.URL, "hello")
+				m.EXPECT().Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q (%q)`, illformed4.URL, "hello")
 			},
 		},
 		"6/illformed": {
 			false,
 			ipnet.IP6, illformed6.URL, ipnet.IP6, invalidIP,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q: %s`, illformed6.URL, "hello")
+				m.EXPECT().Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q (%q)`, illformed6.URL, "hello")
 			},
 		},
 		"4/request-fail": {
diff --git a/internal/provider/protocol/regexp_test.go b/internal/provider/protocol/regexp_test.go
index 632db2b..6565dd1 100644
--- a/internal/provider/protocol/regexp_test.go
+++ b/internal/provider/protocol/regexp_test.go
@@ -85,13 +85,13 @@ func TestRegexpGetIP(t *testing.T) {
 		"4/illformed": {
 			ipnet.IP4, illformed4.URL, regexp.MustCompile(`<<(.*)>>`), ipnet.IP4, invalidIP,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q: %s`, illformed4.URL, "hello")
+				m.EXPECT().Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q (%q)`, illformed4.URL, "hello")
 			},
 		},
 		"6/illformed": {
 			ipnet.IP6, illformed6.URL, regexp.MustCompile(`<<(.*)>>`), ipnet.IP6, invalidIP,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q: %s`, illformed6.URL, "hello")
+				m.EXPECT().Noticef(pp.EmojiError, `Failed to parse the IP address in the response of %q (%q)`, illformed6.URL, "hello")
 			},
 		},
 		"4/request-fail": {
@@ -121,13 +121,13 @@ func TestRegexpGetIP(t *testing.T) {
 		"4/no-match": {
 			ipnet.IP4, illformed4.URL, regexp.MustCompile(`some random string`), ipnet.IP4, invalidIP,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiError, `Failed to find the IP address in the response of %q: %s`, illformed4.URL, []byte("<<hello>>"))
+				m.EXPECT().Noticef(pp.EmojiError, `Failed to find the IP address in the response of %q (%q)`, illformed4.URL, []byte("<<hello>>"))
 			},
 		},
 		"6/no-match": {
 			ipnet.IP6, illformed6.URL, regexp.MustCompile(`some random string`), ipnet.IP6, invalidIP,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiError, `Failed to find the IP address in the response of %q: %s`, illformed6.URL, []byte("<<hello>>"))
+				m.EXPECT().Noticef(pp.EmojiError, `Failed to find the IP address in the response of %q (%q)`, illformed6.URL, []byte("<<hello>>"))
 			},
 		},
 	} {