···4646 ident := ParseIdentity(doc)
4747 declared, err := ident.DeclaredHandle()
4848 if err != nil {
4949- return nil, err
4949+ return nil, fmt.Errorf("could not verify handle/DID match: %w", err)
5050 }
5151 if declared != h {
5252- return nil, ErrHandleMismatch
5252+ return nil, fmt.Errorf("%w: %s != %s", ErrHandleMismatch, declared, h)
5353 }
5454 ident.Handle = declared
5555···6666 if errors.Is(err, ErrHandleNotDeclared) {
6767 ident.Handle = syntax.HandleInvalid
6868 } else if err != nil {
6969- return nil, err
6969+ return nil, fmt.Errorf("could not parse handle from DID document: %w", err)
7070 } else {
7171 // if a handle was declared, resolve it
7272 resolvedDID, err := d.ResolveHandle(ctx, declared)
···9999}
100100101101func (d *BaseDirectory) Purge(ctx context.Context, a syntax.AtIdentifier) error {
102102+ // BaseDirectory itself does not implement caching
102103 return nil
103104}
+3-3
atproto/identity/cache_directory.go
···93939494func (d *CacheDirectory) ResolveHandle(ctx context.Context, h syntax.Handle) (syntax.DID, error) {
9595 if h.IsInvalidHandle() {
9696- return "", fmt.Errorf("invalid handle")
9696+ return "", fmt.Errorf("can not resolve handle: %w", ErrInvalidHandle)
9797 }
9898 entry, ok := d.handleCache.Get(h)
9999 if ok && !d.IsHandleStale(&entry) {
···230230231231 declared, err := ident.DeclaredHandle()
232232 if err != nil {
233233- return nil, hit, err
233233+ return nil, hit, fmt.Errorf("could not verify handle/DID mapping: %w", err)
234234 }
235235 if declared != h {
236236- return nil, hit, ErrHandleMismatch
236236+ return nil, hit, fmt.Errorf("%w: %s != %s", ErrHandleMismatch, declared, h)
237237 }
238238 return ident, hit, nil
239239}
+3
atproto/identity/directory.go
···5252// Indicates that DID document did not include a public key with the specified ID
5353var ErrKeyNotDeclared = errors.New("DID document did not declare a relevant public key")
54545555+// Handle was invalid, in a situation where a valid handle is required.
5656+var ErrInvalidHandle = errors.New("Invalid Handle")
5757+5558var DefaultPLCURL = "https://plc.directory"
56595760// Returns a reasonable Directory implementation for applications
+4-4
atproto/identity/handle.go
···3535 var dnsErr *net.DNSError
3636 if errors.As(err, &dnsErr) {
3737 if dnsErr.IsNotFound {
3838- return "", ErrHandleNotFound
3838+ return "", fmt.Errorf("%w: %s", ErrHandleNotFound, handle)
3939 }
4040 }
4141 if err != nil {
···138138 var dnsErr *net.DNSError
139139 if errors.As(err, &dnsErr) {
140140 if dnsErr.IsNotFound {
141141- return "", fmt.Errorf("%w: DNS NXDOMAIN for %s", ErrHandleNotFound, handle)
141141+ return "", fmt.Errorf("%w: DNS NXDOMAIN for HTTP well-known resolution of %s", ErrHandleNotFound, handle)
142142 }
143143 }
144144 return "", fmt.Errorf("%w: HTTP well-known request error: %w", ErrHandleResolutionFailed, err)
···162162 line := strings.TrimSpace(string(b))
163163 outDid, err := syntax.ParseDID(line)
164164 if err != nil {
165165- return outDid, fmt.Errorf("bad well-known for %s: %w", handle, err)
165165+ return outDid, fmt.Errorf("%w: invalid DID in HTTP well-known for %s", ErrHandleResolutionFailed, handle)
166166 }
167167 return outDid, err
168168}
···173173 var did syntax.DID
174174175175 if handle.IsInvalidHandle() {
176176- return "", fmt.Errorf("invalid handle")
176176+ return "", fmt.Errorf("can not resolve handle: %w", ErrInvalidHandle)
177177 }
178178179179 if !handle.AllowedTLD() {