From 87623a2104415ae63af0ebbfb3071ae45823ca00 Mon Sep 17 00:00:00 2001 From: Evan Vetere Date: Sun, 5 Jul 2026 12:58:36 -0400 Subject: [PATCH] fix: surface specific PowerDNS 422 detail in DNSRecordSet status FriendlyMessage collapsed every unrecognized 422 into a generic "rejected as invalid" message, dropping the pdns `error` field. The real rejection reason then only existed in operator pod logs, leaving `kubectl get dnsrecordset -o yaml` with nothing actionable (surfaced while diagnosing dns-operator#51). Append the specific pdns detail to the generic 422 fallback so the reason reaches the CR status. Known actionable patterns and the empty-body case are unchanged. Refs: #51 Co-Authored-By: Claude Opus 4.8 --- internal/pdns/errors.go | 5 +++++ internal/pdns/errors_test.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/pdns/errors.go b/internal/pdns/errors.go index 2ee6deb..2d834ab 100644 --- a/internal/pdns/errors.go +++ b/internal/pdns/errors.go @@ -48,6 +48,11 @@ func FriendlyMessage(err error) string { case strings.Contains(detail, "RRset") && strings.Contains(detail, "IN ALIAS"): return "An ALIAS record conflicts with an existing record at this name." case apiErr.Status == 422: + // Surface the specific PowerDNS rejection reason when it doesn't match a + // known pattern; without it the reason is only visible in operator logs. + if detail != "" { + return "The DNS record was rejected as invalid: " + detail + } return "The DNS record was rejected as invalid. Check the record type and value." case apiErr.Status == 404: return "The DNS zone could not be found. It may still be provisioning." diff --git a/internal/pdns/errors_test.go b/internal/pdns/errors_test.go index f820d1c..9b41105 100644 --- a/internal/pdns/errors_test.go +++ b/internal/pdns/errors_test.go @@ -51,9 +51,9 @@ func TestFriendlyMessage(t *testing.T) { want: "The DNS record was rejected as invalid. Check the record type and value.", }, { - name: "422 unknown body falls back to generic 422 message", + name: "422 unknown body surfaces the specific pdns detail", err: &pdnsAPIError{Status: 422, Body: `{"error": "Some other validation error"}`}, - want: "The DNS record was rejected as invalid. Check the record type and value.", + want: "The DNS record was rejected as invalid: Some other validation error", }, { name: "404",