Repository: favonia/cloudflare-ddns
Pull request #865 (2024-08-10 21:13:21)

docs: tweak error messages


Patch:
diff --git a/internal/setter/setter.go b/internal/setter/setter.go
index dc770e2..a0965c4 100644
--- a/internal/setter/setter.go
+++ b/internal/setter/setter.go
@@ -256,6 +256,8 @@ func (s setter) SetWAFList(ctx context.Context, ppfmt pp.PP,
 	}
 
 	if !s.Handle.CreateWAFListItems(ctx, ppfmt, listName, itemsToCreate, itemComment) {
+		ppfmt.Warningf(pp.EmojiError, "Failed to properly update the list %q (ID: %s); its content may be inconsistent",
+			listName, listID)
 		return ResponseFailed
 	}
 	for _, item := range itemsToCreate {
@@ -268,6 +270,8 @@ func (s setter) SetWAFList(ctx context.Context, ppfmt pp.PP,
 		idsToDelete = append(idsToDelete, item.ID)
 	}
 	if !s.Handle.DeleteWAFListItems(ctx, ppfmt, listName, idsToDelete) {
+		ppfmt.Warningf(pp.EmojiError, "Failed to properly update the list %q (ID: %s); its content may be inconsistent",
+			listName, listID)
 		return ResponseFailed
 	}
 	for _, item := range itemsToDelete {
diff --git a/internal/updater/message.go b/internal/updater/message.go
index 09804b8..4b9a612 100644
--- a/internal/updater/message.go
+++ b/internal/updater/message.go
@@ -46,7 +46,7 @@ func generateUpdateMessage(ipNet ipnet.Type, ip netip.Addr, s setterResponses) m
 				pp.Join(s[setter.ResponseFailed]),
 			)},
 			NotifierMessages: []string{fmt.Sprintf(
-				"Failed to finish updating %s records of %s with %s; those of %s were updated.",
+				"Failed to properly update %s records of %s with %s; those of %s were updated.",
 				ipNet.RecordType(),
 				pp.EnglishJoin(s[setter.ResponseFailed]),
 				ip.String(),
@@ -64,7 +64,7 @@ func generateUpdateMessage(ipNet ipnet.Type, ip netip.Addr, s setterResponses) m
 				pp.Join(s[setter.ResponseFailed]),
 			)},
 			NotifierMessages: []string{fmt.Sprintf(
-				"Failed to finish updating %s records of %s with %s.",
+				"Failed to properly update %s records of %s with %s.",
 				ipNet.RecordType(),
 				pp.EnglishJoin(s[setter.ResponseFailed]),
 				ip.String(),
@@ -105,7 +105,7 @@ func generateDeleteMessage(ipNet ipnet.Type, s setterResponses) message.Message
 				pp.Join(s[setter.ResponseFailed]),
 			)},
 			NotifierMessages: []string{fmt.Sprintf(
-				"Failed to finish deleting %s records of %s; those of %s were deleted.",
+				"Failed to properly delete %s records of %s; those of %s were deleted.",
 				ipNet.RecordType(),
 				pp.EnglishJoin(s[setter.ResponseFailed]),
 				pp.EnglishJoin(s[setter.ResponseUpdated]),
@@ -121,7 +121,7 @@ func generateDeleteMessage(ipNet ipnet.Type, s setterResponses) message.Message
 				pp.Join(s[setter.ResponseFailed]),
 			)},
 			NotifierMessages: []string{fmt.Sprintf(
-				"Failed to finish deleting %s records of %s.",
+				"Failed to properly delete %s records of %s.",
 				ipNet.RecordType(),
 				pp.EnglishJoin(s[setter.ResponseFailed]),
 			)},
diff --git a/internal/updater/message_waf.go b/internal/updater/message_waf.go
index 45c3d77..1c4dc94 100644
--- a/internal/updater/message_waf.go
+++ b/internal/updater/message_waf.go
@@ -29,7 +29,7 @@ func generateUpdateWAFListMessage(s setterWAFListResponses) message.Message {
 				"Failed to set list(s): " + pp.Join(s[setter.ResponseFailed]),
 			},
 			NotifierMessages: []string{fmt.Sprintf(
-				"Failed to finish updating WAF list(s) %s; %s were updated.",
+				"Failed to properly update WAF list(s) %s; %s were updated.",
 				pp.QuotedEnglishJoin(s[setter.ResponseFailed]),
 				pp.QuotedEnglishJoin(s[setter.ResponseUpdated]),
 			)},
@@ -42,7 +42,7 @@ func generateUpdateWAFListMessage(s setterWAFListResponses) message.Message {
 				"Failed to set list(s): " + pp.Join(s[setter.ResponseFailed]),
 			},
 			NotifierMessages: []string{fmt.Sprintf(
-				"Failed to finish updating WAF list(s) %s.",
+				"Failed to properly update WAF list(s) %s.",
 				pp.QuotedEnglishJoin(s[setter.ResponseFailed]),
 			)},
 		}
@@ -75,7 +75,7 @@ func generateDeleteWAFListMessage(s setterWAFListResponses) message.Message {
 				"Failed to delete list(s): " + pp.Join(s[setter.ResponseFailed]),
 			},
 			NotifierMessages: []string{fmt.Sprintf(
-				"Failed to finish deleting WAF list(s) %s; %s were deleted.",
+				"Failed to properly delete WAF list(s) %s; %s were deleted.",
 				pp.QuotedEnglishJoin(s[setter.ResponseFailed]),
 				pp.QuotedEnglishJoin(s[setter.ResponseUpdated]),
 			)},
@@ -88,7 +88,7 @@ func generateDeleteWAFListMessage(s setterWAFListResponses) message.Message {
 				"Failed to delete list(s): " + pp.Join(s[setter.ResponseFailed]),
 			},
 			NotifierMessages: []string{fmt.Sprintf(
-				"Failed to finish deleting WAF list(s) %s.",
+				"Failed to properly delete WAF list(s) %s.",
 				pp.QuotedEnglishJoin(s[setter.ResponseFailed]),
 			)},
 		}


Test patch:
diff --git a/internal/setter/setter_test.go b/internal/setter/setter_test.go
index f1aa090..c56cce1 100644
--- a/internal/setter/setter_test.go
+++ b/internal/setter/setter_test.go
@@ -586,19 +586,19 @@ func TestSetWAFList(t *testing.T) {
 							prefix4wrong1.ID,
 							prefix6wrong1.ID,
 						})).Return(true),
+					p.EXPECT().Noticef(pp.EmojiDeletion,
+						"Deleted %s from the list %q (ID: %s)", "20.0.0.0/20", listName, listID),
+					p.EXPECT().Noticef(pp.EmojiDeletion,
+						"Deleted %s from the list %q (ID: %s)", "20.0.0.0/24", listName, listID),
+					p.EXPECT().Noticef(pp.EmojiDeletion,
+						"Deleted %s from the list %q (ID: %s)", "20.0.0.0/16", listName, listID),
+					p.EXPECT().Noticef(pp.EmojiDeletion,
+						"Deleted %s from the list %q (ID: %s)", "4001:db8::/40", listName, listID),
+					p.EXPECT().Noticef(pp.EmojiDeletion,
+						"Deleted %s from the list %q (ID: %s)", "4001:db8::/48", listName, listID),
+					p.EXPECT().Noticef(pp.EmojiDeletion,
+						"Deleted %s from the list %q (ID: %s)", "4001:db8::/32", listName, listID),
 				)
-				p.EXPECT().Noticef(pp.EmojiDeletion,
-					"Deleted %s from the list %q (ID: %s)", "20.0.0.0/20", listName, listID)
-				p.EXPECT().Noticef(pp.EmojiDeletion,
-					"Deleted %s from the list %q (ID: %s)", "4001:db8::/40", listName, listID)
-				p.EXPECT().Noticef(pp.EmojiDeletion,
-					"Deleted %s from the list %q (ID: %s)", "4001:db8::/48", listName, listID)
-				p.EXPECT().Noticef(pp.EmojiDeletion,
-					"Deleted %s from the list %q (ID: %s)", "20.0.0.0/24", listName, listID)
-				p.EXPECT().Noticef(pp.EmojiDeletion,
-					"Deleted %s from the list %q (ID: %s)", "20.0.0.0/16", listName, listID)
-				p.EXPECT().Noticef(pp.EmojiDeletion,
-					"Deleted %s from the list %q (ID: %s)", "4001:db8::/32", listName, listID)
 			},
 		},
 		"create-fail": {
@@ -610,6 +610,8 @@ func TestSetWAFList(t *testing.T) {
 					m.EXPECT().ListWAFListItems(ctx, p, listName).Return(items{}, false, true),
 					m.EXPECT().CreateWAFListItems(ctx, p, listName,
 						[]netip.Prefix{prefix4.Prefix, prefix6.Prefix}, "").Return(false),
+					p.EXPECT().Warningf(pp.EmojiError,
+						"Failed to properly update the list %q (ID: %s); its content may be inconsistent", listName, listID),
 				)
 			},
 		},
@@ -644,6 +646,8 @@ func TestSetWAFList(t *testing.T) {
 							prefix4wrong1.ID,
 							prefix6wrong1.ID,
 						})).Return(false),
+					p.EXPECT().Warningf(pp.EmojiError,
+						"Failed to properly update the list %q (ID: %s); its content may be inconsistent", listName, listID),
 				)
 			},
 		},
diff --git a/internal/updater/updater_test.go b/internal/updater/updater_test.go
index 3a4e40e..07424a0 100644
--- a/internal/updater/updater_test.go
+++ b/internal/updater/updater_test.go
@@ -81,9 +81,9 @@ func TestUpdateIPsMultiple(t *testing.T) {
 			false,
 			[]string{"Failed to set A (127.0.0.1): ip4.hello2", "Failed to set list(s): list2"},
 			[]string{
-				"Failed to finish updating A records of ip4.hello2 with 127.0.0.1; " +
+				"Failed to properly update A records of ip4.hello2 with 127.0.0.1; " +
 					"those of ip4.hello1 and ip4.hello4 were updated.",
-				`Failed to finish updating WAF list(s) "list2"; "list1" and "list4" were updated.`,
+				`Failed to properly update WAF list(s) "list2"; "list1" and "list4" were updated.`,
 			},
 			providerEnablers{ipnet.IP4: true},
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) { //nolint:dupl
@@ -192,8 +192,8 @@ func TestDeleteIPsMultiple(t *testing.T) {
 			false,
 			[]string{"Failed to delete A: ip4.hello2", "Failed to delete list(s): list2"},
 			[]string{
-				"Failed to finish deleting A records of ip4.hello2; those of ip4.hello1 and ip4.hello4 were deleted.",
-				`Failed to finish deleting WAF list(s) "list2"; "list1" and "list4" were deleted.`,
+				"Failed to properly delete A records of ip4.hello2; those of ip4.hello1 and ip4.hello4 were deleted.",
+				`Failed to properly delete WAF list(s) "list2"; "list1" and "list4" were deleted.`,
 			},
 			func(p *mocks.MockPP, s *mocks.MockSetter) {
 				gomock.InOrder(
@@ -443,8 +443,8 @@ func TestUpdateIPs(t *testing.T) {
 			false,
 			[]string{"Failed to set A (127.0.0.1): ip4.hello", "Failed to set list(s): list"},
 			[]string{
-				"Failed to finish updating A records of ip4.hello with 127.0.0.1.",
-				`Failed to finish updating WAF list(s) "list".`,
+				"Failed to properly update A records of ip4.hello with 127.0.0.1.",
+				`Failed to properly update WAF list(s) "list".`,
 			},
 			providerEnablers{ipnet.IP4: true},
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) {
@@ -481,8 +481,8 @@ func TestUpdateIPs(t *testing.T) {
 			false,
 			[]string{"Failed to set AAAA (::1): ip6.hello", "Failed to set list(s): list"},
 			[]string{
-				"Failed to finish updating AAAA records of ip6.hello with ::1.",
-				`Failed to finish updating WAF list(s) "list".`,
+				"Failed to properly update AAAA records of ip6.hello with ::1.",
+				`Failed to properly update WAF list(s) "list".`,
 			},
 			providerEnablers{ipnet.IP6: true},
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) {
@@ -518,7 +518,7 @@ func TestUpdateIPs(t *testing.T) {
 		"dual/set-fail/1": {
 			false,
 			[]string{"Failed to set A (127.0.0.1): ip4.hello"},
-			[]string{"Failed to finish updating A records of ip4.hello with 127.0.0.1."},
+			[]string{"Failed to properly update A records of ip4.hello with 127.0.0.1."},
 			providerEnablers{ipnet.IP4: true, ipnet.IP6: true},
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) { //nolint:dupl
 				gomock.InOrder(
@@ -539,7 +539,7 @@ func TestUpdateIPs(t *testing.T) {
 		"dual/set-fail/2": {
 			false,
 			[]string{"Failed to set AAAA (::1): ip6.hello"},
-			[]string{"Failed to finish updating AAAA records of ip6.hello with ::1."},
+			[]string{"Failed to properly update AAAA records of ip6.hello with ::1."},
 			providerEnablers{ipnet.IP4: true, ipnet.IP6: true},
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) { //nolint:dupl
 				gomock.InOrder(
@@ -560,7 +560,7 @@ func TestUpdateIPs(t *testing.T) {
 		"dual/set-fail/3": {
 			false,
 			[]string{`Failed to set list(s): list`},
-			[]string{`Failed to finish updating WAF list(s) "list".`},
+			[]string{`Failed to properly update WAF list(s) "list".`},
 			providerEnablers{ipnet.IP4: true, ipnet.IP6: true},
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) { //nolint:dupl
 				gomock.InOrder(
@@ -659,7 +659,7 @@ func TestUpdateIPs(t *testing.T) {
 		"set-timeout": {
 			false,
 			[]string{"Failed to set A (127.0.0.1): ip4.hello"},
-			[]string{"Failed to finish updating A records of ip4.hello with 127.0.0.1."},
+			[]string{"Failed to properly update A records of ip4.hello with 127.0.0.1."},
 			providerEnablers{ipnet.IP4: true},
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) {
 				gomock.InOrder(
@@ -680,7 +680,7 @@ func TestUpdateIPs(t *testing.T) {
 		"set-list-timeout": {
 			false,
 			[]string{"Failed to set list(s): list"},
-			[]string{`Failed to finish updating WAF list(s) "list".`},
+			[]string{`Failed to properly update WAF list(s) "list".`},
 			providerEnablers{ipnet.IP4: true},
 			func(p *mocks.MockPP, pv mockProviders, s *mocks.MockSetter) {
 				gomock.InOrder(
@@ -769,8 +769,8 @@ func TestDeleteIPs(t *testing.T) {
 			false,
 			[]string{"Failed to delete A: ip4.hello", "Failed to delete list(s): list"},
 			[]string{
-				"Failed to finish deleting A records of ip4.hello.",
-				`Failed to finish deleting WAF list(s) "list".`,
+				"Failed to properly delete A records of ip4.hello.",
+				`Failed to properly delete WAF list(s) "list".`,
 			},
 			mockproviders{ipnet.IP4: true},
 			func(ppfmt *mocks.MockPP, s *mocks.MockSetter) {
@@ -799,8 +799,8 @@ func TestDeleteIPs(t *testing.T) {
 			false,
 			[]string{"Failed to delete AAAA: ip6.hello", "Failed to delete list(s): list"},
 			[]string{
-				"Failed to finish deleting AAAA records of ip6.hello.",
-				`Failed to finish deleting WAF list(s) "list".`,
+				"Failed to properly delete AAAA records of ip6.hello.",
+				`Failed to properly delete WAF list(s) "list".`,
 			},
 			mockproviders{ipnet.IP6: true},
 			func(ppfmt *mocks.MockPP, s *mocks.MockSetter) {
@@ -829,7 +829,7 @@ func TestDeleteIPs(t *testing.T) {
 		"dual/fail/1": {
 			false,
 			[]string{"Failed to delete A: ip4.hello"},
-			[]string{"Failed to finish deleting A records of ip4.hello."},
+			[]string{"Failed to properly delete A records of ip4.hello."},
 			mockproviders{ipnet.IP4: true, ipnet.IP6: true},
 			func(ppfmt *mocks.MockPP, s *mocks.MockSetter) {
 				gomock.InOrder(
@@ -842,7 +842,7 @@ func TestDeleteIPs(t *testing.T) {
 		"dual/fail/2": {
 			false,
 			[]string{"Failed to delete AAAA: ip6.hello"},
-			[]string{"Failed to finish deleting AAAA records of ip6.hello."},
+			[]string{"Failed to properly delete AAAA records of ip6.hello."},
 			mockproviders{ipnet.IP4: true, ipnet.IP6: true},
 			func(ppfmt *mocks.MockPP, s *mocks.MockSetter) {
 				gomock.InOrder(
@@ -855,7 +855,7 @@ func TestDeleteIPs(t *testing.T) {
 		"dual/fail/3": {
 			false,
 			[]string{"Failed to delete list(s): list"},
-			[]string{`Failed to finish deleting WAF list(s) "list".`},
+			[]string{`Failed to properly delete WAF list(s) "list".`},
 			mockproviders{ipnet.IP4: true, ipnet.IP6: true},
 			func(ppfmt *mocks.MockPP, s *mocks.MockSetter) {
 				gomock.InOrder(
@@ -868,7 +868,7 @@ func TestDeleteIPs(t *testing.T) {
 		"delete-timeout": {
 			false,
 			[]string{"Failed to delete A: ip4.hello"},
-			[]string{"Failed to finish deleting A records of ip4.hello."},
+			[]string{"Failed to properly delete A records of ip4.hello."},
 			mockproviders{ipnet.IP4: true},
 			func(ppfmt *mocks.MockPP, s *mocks.MockSetter) {
 				gomock.InOrder(
@@ -886,7 +886,7 @@ func TestDeleteIPs(t *testing.T) {
 		"delete-list-timeout": {
 			false,
 			[]string{"Failed to delete list(s): list"},
-			[]string{`Failed to finish deleting WAF list(s) "list".`},
+			[]string{`Failed to properly delete WAF list(s) "list".`},
 			mockproviders{ipnet.IP4: true},
 			func(ppfmt *mocks.MockPP, s *mocks.MockSetter) {
 				gomock.InOrder(