Skip to content

Commit

Permalink
identity: small improvements (#458)
Browse files Browse the repository at this point in the history
I'm not sure why the error wasn't getting returned; might have been a
typo? Probably worth re-reading that function again in review. I hit a
nil de-reference pointer in automod caused by that function returning
`nil, nil`.
  • Loading branch information
bnewbold authored Nov 29, 2023
2 parents 77d80d3 + 218e525 commit 81f67da
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions atproto/identity/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type BaseDirectory struct {
var _ Directory = (*BaseDirectory)(nil)

func (d *BaseDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) {
h = h.Normalize()
did, err := d.ResolveHandle(ctx, h)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion atproto/identity/cache_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (d *CacheDirectory) updateDID(ctx context.Context, did syntax.DID) (*Identi
if he != nil {
d.handleCache.Add(ident.Handle, *he)
}
return &entry, nil
return &entry, err
}

func (d *CacheDirectory) LookupDID(ctx context.Context, did syntax.DID) (*Identity, error) {
Expand Down Expand Up @@ -226,6 +226,7 @@ func (d *CacheDirectory) LookupDID(ctx context.Context, did syntax.DID) (*Identi
}

func (d *CacheDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) {
h = h.Normalize()
did, err := d.ResolveHandle(ctx, h)
if err != nil {
return nil, err
Expand Down Expand Up @@ -260,6 +261,7 @@ func (d *CacheDirectory) Lookup(ctx context.Context, a syntax.AtIdentifier) (*Id
func (d *CacheDirectory) Purge(ctx context.Context, a syntax.AtIdentifier) error {
handle, err := a.AsHandle()
if nil == err { // if not an error, is a handle
handle = handle.Normalize()
d.handleCache.Remove(handle)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions atproto/identity/mock_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (d *MockDirectory) Insert(ident Identity) {
}

func (d *MockDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) {
h = h.Normalize()
did, ok := d.Handles[h]
if !ok {
return nil, ErrHandleNotFound
Expand Down

0 comments on commit 81f67da

Please sign in to comment.