@@ -88,6 +88,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options
88
88
89
89
go func () {
90
90
defer close (out )
91
+ var rootResErr , subResErr error
91
92
for {
92
93
select {
93
94
case subRes , ok := <- subChan :
@@ -100,6 +101,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options
100
101
emitOnceResult (ctx , out , onceResult {value : p , err : err })
101
102
return
102
103
}
104
+ subResErr = subRes .error
103
105
case rootRes , ok := <- rootChan :
104
106
if ! ok {
105
107
rootChan = nil
@@ -108,11 +110,26 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options
108
110
if rootRes .error == nil {
109
111
p , err := appendPath (rootRes .path )
110
112
emitOnceResult (ctx , out , onceResult {value : p , err : err })
113
+ return
111
114
}
115
+ rootResErr = rootRes .error
112
116
case <- ctx .Done ():
113
117
return
114
118
}
115
119
if subChan == nil && rootChan == nil {
120
+ // If here, then both lookups failed
121
+ //
122
+ // If both lookup errors were due to no TXT records with a
123
+ // dnslink, then output a more specific error message
124
+ if rootResErr == ErrResolveFailed && subResErr == ErrResolveFailed {
125
+ i := len (name ) - 1
126
+ for i >= 0 && name [i ] != '/' {
127
+ i --
128
+ }
129
+ // Wrap error so that it can be tested if it is a ErrResolveFailed
130
+ err := fmt .Errorf ("%w: %q is missing a DNSLink record (https://docs.ipfs.io/concepts/dnslink/)" , ErrResolveFailed , name [i + 1 :])
131
+ emitOnceResult (ctx , out , onceResult {err : err })
132
+ }
116
133
return
117
134
}
118
135
}
@@ -126,7 +143,14 @@ func workDomain(r *DNSResolver, name string, res chan lookupRes) {
126
143
127
144
txt , err := r .lookupTXT (name )
128
145
if err != nil {
129
- // Error is != nil
146
+ if dnsErr , ok := err .(* net.DNSError ); ok {
147
+ // If no TXT records found, return same error as when no text
148
+ // records contain dnslink. Otherwise, return the actual error.
149
+ if dnsErr .IsNotFound {
150
+ err = ErrResolveFailed
151
+ }
152
+ }
153
+ // Could not look up any text records for name
130
154
res <- lookupRes {"" , err }
131
155
return
132
156
}
@@ -138,6 +162,8 @@ func workDomain(r *DNSResolver, name string, res chan lookupRes) {
138
162
return
139
163
}
140
164
}
165
+
166
+ // There were no TXT records with a dnslink
141
167
res <- lookupRes {"" , ErrResolveFailed }
142
168
}
143
169
0 commit comments