Skip to content

Commit 09e0436

Browse files
authored
Error: change a whole bunch error messages' prefix (#1657)
* Error: change a whole bunch error messages' prefix Long ago we started using 'bad ...' as the error messages, the "dns:" prefix is used for panic's not in normal errors, remove are replace a whole bunch of "dns:" with "bad ..." Signed-off-by: Miek Gieben <[email protected]> * Error: change a whole bunch error messages' prefix Long ago we started using 'bad ...' as the error messages, the "dns:" prefix is used for panic's not in normal errors, remove are replace a whole bunch of "dns:" with "bad ..." Signed-off-by: Miek Gieben <[email protected]> * Use "bad" here too and use terminoloy from Msg struct Extra instead of Ar count Signed-off-by: Miek Gieben <[email protected]> --------- Signed-off-by: Miek Gieben <[email protected]>
1 parent 186ccfb commit 09e0436

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

edns.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,30 +317,30 @@ func (e *EDNS0_SUBNET) pack() ([]byte, error) {
317317
// "dig" sets AddressFamily to 0 if SourceNetmask is also 0
318318
// We might don't need to complain either
319319
if e.SourceNetmask != 0 {
320-
return nil, errors.New("dns: bad address family")
320+
return nil, errors.New("bad address family")
321321
}
322322
case 1:
323323
if e.SourceNetmask > net.IPv4len*8 {
324-
return nil, errors.New("dns: bad netmask")
324+
return nil, errors.New("bad netmask")
325325
}
326326
if len(e.Address.To4()) != net.IPv4len {
327-
return nil, errors.New("dns: bad address")
327+
return nil, errors.New("bad address")
328328
}
329329
ip := e.Address.To4().Mask(net.CIDRMask(int(e.SourceNetmask), net.IPv4len*8))
330330
needLength := (e.SourceNetmask + 8 - 1) / 8 // division rounding up
331331
b = append(b, ip[:needLength]...)
332332
case 2:
333333
if e.SourceNetmask > net.IPv6len*8 {
334-
return nil, errors.New("dns: bad netmask")
334+
return nil, errors.New("bad netmask")
335335
}
336336
if len(e.Address) != net.IPv6len {
337-
return nil, errors.New("dns: bad address")
337+
return nil, errors.New("bad address")
338338
}
339339
ip := e.Address.Mask(net.CIDRMask(int(e.SourceNetmask), net.IPv6len*8))
340340
needLength := (e.SourceNetmask + 8 - 1) / 8 // division rounding up
341341
b = append(b, ip[:needLength]...)
342342
default:
343-
return nil, errors.New("dns: bad address family")
343+
return nil, errors.New("bad address family")
344344
}
345345
return b, nil
346346
}
@@ -357,25 +357,25 @@ func (e *EDNS0_SUBNET) unpack(b []byte) error {
357357
// "dig" sets AddressFamily to 0 if SourceNetmask is also 0
358358
// It's okay to accept such a packet
359359
if e.SourceNetmask != 0 {
360-
return errors.New("dns: bad address family")
360+
return errors.New("bad address family")
361361
}
362362
e.Address = net.IPv4(0, 0, 0, 0)
363363
case 1:
364364
if e.SourceNetmask > net.IPv4len*8 || e.SourceScope > net.IPv4len*8 {
365-
return errors.New("dns: bad netmask")
365+
return errors.New("bad netmask")
366366
}
367367
addr := make(net.IP, net.IPv4len)
368368
copy(addr, b[4:])
369369
e.Address = addr.To16()
370370
case 2:
371371
if e.SourceNetmask > net.IPv6len*8 || e.SourceScope > net.IPv6len*8 {
372-
return errors.New("dns: bad netmask")
372+
return errors.New("bad netmask")
373373
}
374374
addr := make(net.IP, net.IPv6len)
375375
copy(addr, b[4:])
376376
e.Address = addr
377377
default:
378-
return errors.New("dns: bad address family")
378+
return errors.New("bad address family")
379379
}
380380
return nil
381381
}
@@ -720,7 +720,7 @@ func (e *EDNS0_TCP_KEEPALIVE) unpack(b []byte) error {
720720
case 2:
721721
e.Timeout = binary.BigEndian.Uint16(b)
722722
default:
723-
return fmt.Errorf("dns: length mismatch, want 0/2 but got %d", len(b))
723+
return fmt.Errorf("length mismatch, want 0/2 but got %d", len(b))
724724
}
725725
return nil
726726
}

msg.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,21 +1123,21 @@ func unpackQuestion(msg []byte, off int) (Question, int, error) {
11231123
)
11241124
q.Name, off, err = UnpackDomainName(msg, off)
11251125
if err != nil {
1126-
return q, off, fmt.Errorf("question.Name: %w", err)
1126+
return q, off, fmt.Errorf("bad question name: %w", err)
11271127
}
11281128
if off == len(msg) {
11291129
return q, off, nil
11301130
}
11311131
q.Qtype, off, err = unpackUint16(msg, off)
11321132
if err != nil {
1133-
return q, off, fmt.Errorf("question.Qtype: %w", err)
1133+
return q, off, fmt.Errorf("bad question qtype: %w", err)
11341134
}
11351135
if off == len(msg) {
11361136
return q, off, nil
11371137
}
11381138
q.Qclass, off, err = unpackUint16(msg, off)
11391139
if err != nil {
1140-
return q, off, fmt.Errorf("question.Qclass: %w", err)
1140+
return q, off, fmt.Errorf("bad question qclass: %w", err)
11411141
}
11421142

11431143
if off == len(msg) {
@@ -1182,27 +1182,27 @@ func unpackMsgHdr(msg []byte, off int) (Header, int, error) {
11821182
)
11831183
dh.Id, off, err = unpackUint16(msg, off)
11841184
if err != nil {
1185-
return dh, off, fmt.Errorf("header.Id: %w", err)
1185+
return dh, off, fmt.Errorf("bad header id: %w", err)
11861186
}
11871187
dh.Bits, off, err = unpackUint16(msg, off)
11881188
if err != nil {
1189-
return dh, off, fmt.Errorf("header.Bits: %w", err)
1189+
return dh, off, fmt.Errorf("bad header bits: %w", err)
11901190
}
11911191
dh.Qdcount, off, err = unpackUint16(msg, off)
11921192
if err != nil {
1193-
return dh, off, fmt.Errorf("header.Qdcount: %w", err)
1193+
return dh, off, fmt.Errorf("bad header question count: %w", err)
11941194
}
11951195
dh.Ancount, off, err = unpackUint16(msg, off)
11961196
if err != nil {
1197-
return dh, off, fmt.Errorf("header.Ancount: %w", err)
1197+
return dh, off, fmt.Errorf("bad header answer count: %w", err)
11981198
}
11991199
dh.Nscount, off, err = unpackUint16(msg, off)
12001200
if err != nil {
1201-
return dh, off, fmt.Errorf("header.Nscount: %w", err)
1201+
return dh, off, fmt.Errorf("bad header ns count: %w", err)
12021202
}
12031203
dh.Arcount, off, err = unpackUint16(msg, off)
12041204
if err != nil {
1205-
return dh, off, fmt.Errorf("header.Arcount: %w", err)
1205+
return dh, off, fmt.Errorf("bad header extra count: %w", err)
12061206
}
12071207
return dh, off, nil
12081208
}

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func (srv *Server) ListenAndServe() error {
335335
return srv.serveTCP(l)
336336
case "tcp-tls", "tcp4-tls", "tcp6-tls":
337337
if srv.TLSConfig == nil || (len(srv.TLSConfig.Certificates) == 0 && srv.TLSConfig.GetCertificate == nil) {
338-
return errors.New("dns: neither Certificates nor GetCertificate set in Config")
338+
return errors.New("neither Certificates nor GetCertificate set in config")
339339
}
340340
network := strings.TrimSuffix(srv.Net, "-tls")
341341
l, err := listenTCP(network, addr, srv.ReusePort, srv.ReuseAddr)

svcb.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func (s *SVCBMandatory) pack() ([]byte, error) {
298298

299299
func (s *SVCBMandatory) unpack(b []byte) error {
300300
if len(b)%2 != 0 {
301-
return errors.New("dns: svcbmandatory: value length is not a multiple of 2")
301+
return errors.New("bad svcbmandatory: value length is not a multiple of 2")
302302
}
303303
codes := make([]SVCBKey, 0, len(b)/2)
304304
for i := 0; i < len(b); i += 2 {
@@ -395,10 +395,10 @@ func (s *SVCBAlpn) pack() ([]byte, error) {
395395
b := make([]byte, 0, 10*len(s.Alpn))
396396
for _, e := range s.Alpn {
397397
if e == "" {
398-
return nil, errors.New("dns: svcbalpn: empty alpn-id")
398+
return nil, errors.New("bad svcbalpn: empty alpn-id")
399399
}
400400
if len(e) > 255 {
401-
return nil, errors.New("dns: svcbalpn: alpn-id too long")
401+
return nil, errors.New("bad svcbalpn: alpn-id too long")
402402
}
403403
b = append(b, byte(len(e)))
404404
b = append(b, e...)
@@ -413,7 +413,7 @@ func (s *SVCBAlpn) unpack(b []byte) error {
413413
length := int(b[i])
414414
i++
415415
if i+length > len(b) {
416-
return errors.New("dns: svcbalpn: alpn array overflowing")
416+
return errors.New("bad svcbalpn: alpn array overflowing")
417417
}
418418
alpn = append(alpn, string(b[i:i+length]))
419419
i += length
@@ -433,13 +433,13 @@ func (s *SVCBAlpn) parse(b string) error {
433433
for p := 0; p < len(b); {
434434
c, q := nextByte(b, p)
435435
if q == 0 {
436-
return errors.New("dns: svcbalpn: unterminated escape")
436+
return errors.New("bad svcbalpn: unterminated escape")
437437
}
438438
p += q
439439
// If we find a comma, we have finished reading an alpn.
440440
if c == ',' {
441441
if len(a) == 0 {
442-
return errors.New("dns: svcbalpn: empty protocol identifier")
442+
return errors.New("bad svcbalpn: empty protocol identifier")
443443
}
444444
alpn = append(alpn, string(a))
445445
a = []byte{}
@@ -449,10 +449,10 @@ func (s *SVCBAlpn) parse(b string) error {
449449
if c == '\\' {
450450
dc, dq := nextByte(b, p)
451451
if dq == 0 {
452-
return errors.New("dns: svcbalpn: unterminated escape decoding comma-separated list")
452+
return errors.New("bad svcbalpn: unterminated escape decoding comma-separated list")
453453
}
454454
if dc != '\\' && dc != ',' {
455-
return errors.New("dns: svcbalpn: bad escaped character decoding comma-separated list")
455+
return errors.New("bad svcbalpn: bad escaped character decoding comma-separated list")
456456
}
457457
p += dq
458458
c = dc
@@ -461,7 +461,7 @@ func (s *SVCBAlpn) parse(b string) error {
461461
}
462462
// Add the final alpn.
463463
if len(a) == 0 {
464-
return errors.New("dns: svcbalpn: last protocol identifier empty")
464+
return errors.New("bad svcbalpn: last protocol identifier empty")
465465
}
466466
s.Alpn = append(alpn, string(a))
467467
return nil
@@ -499,14 +499,14 @@ func (*SVCBNoDefaultAlpn) len() int { return 0 }
499499

500500
func (*SVCBNoDefaultAlpn) unpack(b []byte) error {
501501
if len(b) != 0 {
502-
return errors.New("dns: svcbnodefaultalpn: no-default-alpn must have no value")
502+
return errors.New("bad svcbnodefaultalpn: no-default-alpn must have no value")
503503
}
504504
return nil
505505
}
506506

507507
func (*SVCBNoDefaultAlpn) parse(b string) error {
508508
if b != "" {
509-
return errors.New("dns: svcbnodefaultalpn: no-default-alpn must have no value")
509+
return errors.New("bad svcbnodefaultalpn: no-default-alpn must have no value")
510510
}
511511
return nil
512512
}
@@ -529,7 +529,7 @@ func (s *SVCBPort) copy() SVCBKeyValue { return &SVCBPort{s.Port} }
529529

530530
func (s *SVCBPort) unpack(b []byte) error {
531531
if len(b) != 2 {
532-
return errors.New("dns: svcbport: port length is not exactly 2 octets")
532+
return errors.New("bad svcbport: port length is not exactly 2 octets")
533533
}
534534
s.Port = binary.BigEndian.Uint16(b)
535535
return nil
@@ -544,7 +544,7 @@ func (s *SVCBPort) pack() ([]byte, error) {
544544
func (s *SVCBPort) parse(b string) error {
545545
port, err := strconv.ParseUint(b, 10, 16)
546546
if err != nil {
547-
return errors.New("dns: svcbport: port out of range")
547+
return errors.New("bad svcbport: port out of range")
548548
}
549549
s.Port = uint16(port)
550550
return nil
@@ -577,7 +577,7 @@ func (s *SVCBIPv4Hint) pack() ([]byte, error) {
577577
for _, e := range s.Hint {
578578
x := e.To4()
579579
if x == nil {
580-
return nil, errors.New("dns: svcbipv4hint: expected ipv4, hint is ipv6")
580+
return nil, errors.New("bad svcbipv4hint: expected ipv4, hint is ipv6")
581581
}
582582
b = append(b, x...)
583583
}
@@ -586,7 +586,7 @@ func (s *SVCBIPv4Hint) pack() ([]byte, error) {
586586

587587
func (s *SVCBIPv4Hint) unpack(b []byte) error {
588588
if len(b) == 0 || len(b)%4 != 0 {
589-
return errors.New("dns: svcbipv4hint: ipv4 address byte array length is not a multiple of 4")
589+
return errors.New("bad svcbipv4hint: ipv4 address byte array length is not a multiple of 4")
590590
}
591591
b = cloneSlice(b)
592592
x := make([]net.IP, 0, len(b)/4)
@@ -611,10 +611,10 @@ func (s *SVCBIPv4Hint) String() string {
611611

612612
func (s *SVCBIPv4Hint) parse(b string) error {
613613
if b == "" {
614-
return errors.New("dns: svcbipv4hint: empty hint")
614+
return errors.New("bad svcbipv4hint: empty hint")
615615
}
616616
if strings.Contains(b, ":") {
617-
return errors.New("dns: svcbipv4hint: expected ipv4, got ipv6")
617+
return errors.New("bad svcbipv4hint: expected ipv4, got ipv6")
618618
}
619619

620620
hint := make([]net.IP, 0, strings.Count(b, ",")+1)
@@ -623,7 +623,7 @@ func (s *SVCBIPv4Hint) parse(b string) error {
623623
e, b, _ = strings.Cut(b, ",")
624624
ip := net.ParseIP(e).To4()
625625
if ip == nil {
626-
return errors.New("dns: svcbipv4hint: bad ip")
626+
return errors.New("bad svcbipv4hint: bad ip")
627627
}
628628
hint = append(hint, ip)
629629
}
@@ -671,7 +671,7 @@ func (s *SVCBECHConfig) unpack(b []byte) error {
671671
func (s *SVCBECHConfig) parse(b string) error {
672672
x, err := fromBase64([]byte(b))
673673
if err != nil {
674-
return errors.New("dns: svcbech: bad base64 ech")
674+
return errors.New("bad svcbech: bad base64 ech")
675675
}
676676
s.ECH = x
677677
return nil
@@ -699,7 +699,7 @@ func (s *SVCBIPv6Hint) pack() ([]byte, error) {
699699
b := make([]byte, 0, 16*len(s.Hint))
700700
for _, e := range s.Hint {
701701
if len(e) != net.IPv6len || e.To4() != nil {
702-
return nil, errors.New("dns: svcbipv6hint: expected ipv6, hint is ipv4")
702+
return nil, errors.New("bad svcbipv6hint: expected ipv6, hint is ipv4")
703703
}
704704
b = append(b, e...)
705705
}
@@ -708,14 +708,14 @@ func (s *SVCBIPv6Hint) pack() ([]byte, error) {
708708

709709
func (s *SVCBIPv6Hint) unpack(b []byte) error {
710710
if len(b) == 0 || len(b)%16 != 0 {
711-
return errors.New("dns: svcbipv6hint: ipv6 address byte array length not a multiple of 16")
711+
return errors.New("bas svcbipv6hint: ipv6 address byte array length not a multiple of 16")
712712
}
713713
b = cloneSlice(b)
714714
x := make([]net.IP, 0, len(b)/16)
715715
for i := 0; i < len(b); i += 16 {
716716
ip := net.IP(b[i : i+16])
717717
if ip.To4() != nil {
718-
return errors.New("dns: svcbipv6hint: expected ipv6, got ipv4")
718+
return errors.New("bad svcbipv6hint: expected ipv6, got ipv4")
719719
}
720720
x = append(x, ip)
721721
}
@@ -736,7 +736,7 @@ func (s *SVCBIPv6Hint) String() string {
736736

737737
func (s *SVCBIPv6Hint) parse(b string) error {
738738
if b == "" {
739-
return errors.New("dns: svcbipv6hint: empty hint")
739+
return errors.New("bad svcbipv6hint: empty hint")
740740
}
741741

742742
hint := make([]net.IP, 0, strings.Count(b, ",")+1)
@@ -745,10 +745,10 @@ func (s *SVCBIPv6Hint) parse(b string) error {
745745
e, b, _ = strings.Cut(b, ",")
746746
ip := net.ParseIP(e)
747747
if ip == nil {
748-
return errors.New("dns: svcbipv6hint: bad ip")
748+
return errors.New("bad svcbipv6hint: bad ip")
749749
}
750750
if ip.To4() != nil {
751-
return errors.New("dns: svcbipv6hint: expected ipv6, got ipv4-mapped-ipv6")
751+
return errors.New("bad svcbipv6hint: expected ipv6, got ipv4-mapped-ipv6")
752752
}
753753
hint = append(hint, ip)
754754
}
@@ -800,7 +800,7 @@ func (s *SVCBDoHPath) unpack(b []byte) error {
800800
func (s *SVCBDoHPath) parse(b string) error {
801801
template, err := svcbParseParam(b)
802802
if err != nil {
803-
return fmt.Errorf("dns: svcbdohpath: %w", err)
803+
return fmt.Errorf("bad svcbdohpath: %w", err)
804804
}
805805
s.Template = string(template)
806806
return nil
@@ -838,14 +838,14 @@ func (*SVCBOhttp) len() int { return 0 }
838838

839839
func (*SVCBOhttp) unpack(b []byte) error {
840840
if len(b) != 0 {
841-
return errors.New("dns: svcbotthp: svcbotthp must have no value")
841+
return errors.New("bad svcbotthp: svcbotthp must have no value")
842842
}
843843
return nil
844844
}
845845

846846
func (*SVCBOhttp) parse(b string) error {
847847
if b != "" {
848-
return errors.New("dns: svcbotthp: svcbotthp must have no value")
848+
return errors.New("bad svcbotthp: svcbotthp must have no value")
849849
}
850850
return nil
851851
}
@@ -878,7 +878,7 @@ func (s *SVCBLocal) unpack(b []byte) error {
878878
func (s *SVCBLocal) parse(b string) error {
879879
data, err := svcbParseParam(b)
880880
if err != nil {
881-
return fmt.Errorf("dns: svcblocal: svcb private/experimental key %w", err)
881+
return fmt.Errorf("bad svcblocal: svcb private/experimental key %w", err)
882882
}
883883
s.Data = data
884884
return nil

0 commit comments

Comments
 (0)