mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-09 17:16:50 +00:00
util/dnsname: use vizerror for all errors
The errors emitted by util/dnsname are all written at least moderately friendly and none of them emit sensitive information. They should be safe to display to end users. Updates tailscale/corp#9025 Change-Id: Ic58705075bacf42f56378127532c5f28ff6bfc89 Signed-off-by: Adrian Dewhurst <adrian@tailscale.com>
This commit is contained in:
parent
c9188d7760
commit
716cb37256
@ -5,9 +5,9 @@
|
|||||||
package dnsname
|
package dnsname
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"tailscale.com/util/vizerror"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -36,7 +36,7 @@ func ToFQDN(s string) (FQDN, error) {
|
|||||||
totalLen += 1 // account for missing dot
|
totalLen += 1 // account for missing dot
|
||||||
}
|
}
|
||||||
if totalLen > maxNameLength {
|
if totalLen > maxNameLength {
|
||||||
return "", fmt.Errorf("%q is too long to be a DNS name", s)
|
return "", vizerror.Errorf("%q is too long to be a DNS name", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
st := 0
|
st := 0
|
||||||
@ -54,7 +54,7 @@ func ToFQDN(s string) (FQDN, error) {
|
|||||||
//
|
//
|
||||||
// See https://github.com/tailscale/tailscale/issues/2024 for more.
|
// See https://github.com/tailscale/tailscale/issues/2024 for more.
|
||||||
if len(label) == 0 || len(label) > maxLabelLength {
|
if len(label) == 0 || len(label) > maxLabelLength {
|
||||||
return "", fmt.Errorf("%q is not a valid DNS label", label)
|
return "", vizerror.Errorf("%q is not a valid DNS label", label)
|
||||||
}
|
}
|
||||||
st = i + 1
|
st = i + 1
|
||||||
}
|
}
|
||||||
@ -97,23 +97,23 @@ func (f FQDN) Contains(other FQDN) bool {
|
|||||||
// ValidLabel reports whether label is a valid DNS label.
|
// ValidLabel reports whether label is a valid DNS label.
|
||||||
func ValidLabel(label string) error {
|
func ValidLabel(label string) error {
|
||||||
if len(label) == 0 {
|
if len(label) == 0 {
|
||||||
return errors.New("empty DNS label")
|
return vizerror.New("empty DNS label")
|
||||||
}
|
}
|
||||||
if len(label) > maxLabelLength {
|
if len(label) > maxLabelLength {
|
||||||
return fmt.Errorf("%q is too long, max length is %d bytes", label, maxLabelLength)
|
return vizerror.Errorf("%q is too long, max length is %d bytes", label, maxLabelLength)
|
||||||
}
|
}
|
||||||
if !isalphanum(label[0]) {
|
if !isalphanum(label[0]) {
|
||||||
return fmt.Errorf("%q is not a valid DNS label: must start with a letter or number", label)
|
return vizerror.Errorf("%q is not a valid DNS label: must start with a letter or number", label)
|
||||||
}
|
}
|
||||||
if !isalphanum(label[len(label)-1]) {
|
if !isalphanum(label[len(label)-1]) {
|
||||||
return fmt.Errorf("%q is not a valid DNS label: must end with a letter or number", label)
|
return vizerror.Errorf("%q is not a valid DNS label: must end with a letter or number", label)
|
||||||
}
|
}
|
||||||
if len(label) < 2 {
|
if len(label) < 2 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for i := 1; i < len(label)-1; i++ {
|
for i := 1; i < len(label)-1; i++ {
|
||||||
if !isdnschar(label[i]) {
|
if !isdnschar(label[i]) {
|
||||||
return fmt.Errorf("%q is not a valid DNS label: contains invalid character %q", label, label[i])
|
return vizerror.Errorf("%q is not a valid DNS label: contains invalid character %q", label, label[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user