-
Notifications
You must be signed in to change notification settings - Fork 10
Properly report DNSLink errors #12
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options | |
|
||
go func() { | ||
defer close(out) | ||
var rootResErr, subResErr error | ||
for { | ||
select { | ||
case subRes, ok := <-subChan: | ||
|
@@ -100,6 +101,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options | |
emitOnceResult(ctx, out, onceResult{value: p, err: err}) | ||
return | ||
} | ||
subResErr = subRes.error | ||
case rootRes, ok := <-rootChan: | ||
if !ok { | ||
rootChan = nil | ||
|
@@ -108,11 +110,26 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options | |
if rootRes.error == nil { | ||
p, err := appendPath(rootRes.path) | ||
emitOnceResult(ctx, out, onceResult{value: p, err: err}) | ||
return | ||
} | ||
rootResErr = rootRes.error | ||
case <-ctx.Done(): | ||
return | ||
} | ||
if subChan == nil && rootChan == nil { | ||
// If here, then both lookups failed | ||
// | ||
// If both lookup errors were due to no TXT records with a | ||
// dnslink, then output a more specific error message | ||
if rootResErr == ErrResolveFailed && subResErr == ErrResolveFailed { | ||
i := len(name) - 1 | ||
for i >= 0 && name[i] != '/' { | ||
i-- | ||
} | ||
aschmahmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Wrap error so that it can be tested if it is a ErrResolveFailed | ||
err := fmt.Errorf("%w: %q is missing a DNSLink record (https://docs.ipfs.io/concepts/dnslink/)", ErrResolveFailed, name[i+1:]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean "is missing a DNSLink record, or the host could not be found" (or some phrasing like that)? It looks like we're also covering There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error covers both. So, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If your machine is offline to you also get a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. You do not. I determine that by checking the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The DNSError struct documentation is kind of sparse ("host not found" seems like it could mean a bunch of things). If you've tested that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes tested |
||
emitOnceResult(ctx, out, onceResult{err: err}) | ||
} | ||
return | ||
} | ||
} | ||
|
@@ -126,7 +143,14 @@ func workDomain(r *DNSResolver, name string, res chan lookupRes) { | |
|
||
txt, err := r.lookupTXT(name) | ||
if err != nil { | ||
// Error is != nil | ||
if dnsErr, ok := err.(*net.DNSError); ok { | ||
// If no TXT records found, return same error as when no text | ||
// records contain dnslink. Otherwise, return the actual error. | ||
if dnsErr.IsNotFound { | ||
err = ErrResolveFailed | ||
} | ||
} | ||
// Could not look up any text records for name | ||
res <- lookupRes{"", err} | ||
return | ||
} | ||
|
@@ -138,6 +162,8 @@ func workDomain(r *DNSResolver, name string, res chan lookupRes) { | |
return | ||
} | ||
} | ||
|
||
// There were no TXT records with a dnslink | ||
res <- lookupRes{"", ErrResolveFailed} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.