Commit 74f3bea5 authored by Ben Kochie's avatar Ben Kochie Committed by GitHub

Convert HostPortOrFile error to var (#5058)

Convert "no nameservers found" error on parse.HostPortOrFile() to an
exported var for use with `errors.Is()`.
Signed-off-by: default avatarSuperQ <superq@gmail.com>
parent b53aac99
package parse
import (
"errors"
"fmt"
"net"
"os"
......@@ -11,6 +12,9 @@ import (
"github.com/miekg/dns"
)
// ErrNoNameservers is returned by HostPortOrFile if no servers can be parsed.
var ErrNoNameservers = errors.New("no nameservers found")
// Strips the zone, but preserves any port that comes after the zone
func stripZone(host string) string {
if strings.Contains(host, "%") {
......@@ -70,7 +74,7 @@ func HostPortOrFile(s ...string) ([]string, error) {
servers = append(servers, h)
}
if len(servers) == 0 {
return servers, fmt.Errorf("no nameservers found")
return servers, ErrNoNameservers
}
return servers, nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment