Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,42 @@ import (
func LookupPort(network, service string) (port int, err error) {
return 0, errors.New("net:LookupPort not implemented")
}

// DNSError represents a DNS lookup error.
//
// TINYGO: Trimmed copy of the standard library's net.DNSError so that name
// resolution errors keep a familiar, type-assertable shape.
type DNSError struct {
UnwrapErr error // error returned by the [DNSError.Unwrap] method, might be nil
Err string // description of the error
Name string // name looked for
Server string // server used
IsTimeout bool // if true, timed out; not all timeouts set this
IsTemporary bool // if true, error is temporary; not all errors set this

// IsNotFound is set to true when the requested name does not
// contain any records of the requested type (data not found),
// or the name itself was not found (NXDOMAIN).
IsNotFound bool
}

// Unwrap returns e.UnwrapErr.
func (e *DNSError) Unwrap() error { return e.UnwrapErr }

func (e *DNSError) Error() string {
if e == nil {
return "<nil>"
}
s := "lookup " + e.Name
if e.Server != "" {
s += " on " + e.Server
}
s += ": " + e.Err
return s
}

// Timeout reports whether the DNS lookup is known to have timed out.
func (e *DNSError) Timeout() bool { return e.IsTimeout }

// Temporary reports whether the DNS error is known to be temporary.
func (e *DNSError) Temporary() bool { return e.IsTimeout || e.IsTemporary }
Loading