Skip to content

Commit

Permalink
refactor: use ppfmt.Warningf more (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia authored Jul 27, 2024
1 parent 17d2d32 commit dfe38f6
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/notifier/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/shoutrrr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
},
} {
Expand Down
2 changes: 1 addition & 1 deletion internal/pp/verbosity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/protocol/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/protocol/doh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/protocol/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/protocol/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions internal/setter/setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/setter/setter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
},
},
Expand All @@ -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
)
},
},
Expand Down Expand Up @@ -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
)
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions internal/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
},
},
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
)
},
Expand Down

0 comments on commit dfe38f6

Please sign in to comment.