Skip to content

Commit

Permalink
replace fmt.Errorf with errors.New for static strings
Browse files Browse the repository at this point in the history
  • Loading branch information
bnewbold committed Sep 28, 2024
1 parent 873a739 commit dc4176c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions atproto/identity/redisdir/redis_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redisdir

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -160,7 +161,7 @@ func (d *RedisDirectory) updateHandle(ctx context.Context, h syntax.Handle) hand

func (d *RedisDirectory) ResolveHandle(ctx context.Context, h syntax.Handle) (syntax.DID, error) {
if h.IsInvalidHandle() {
return "", fmt.Errorf("invalid handle")
return "", errors.New("invalid handle")
}
var entry handleEntry
err := d.handleCache.Get(ctx, redisDirPrefix+h.String(), &entry)
Expand All @@ -174,7 +175,7 @@ func (d *RedisDirectory) ResolveHandle(ctx context.Context, h syntax.Handle) (sy
} else if entry.DID != nil {
return *entry.DID, nil
} else {
return "", fmt.Errorf("code flow error in redis identity directory")
return "", errors.New("code flow error in redis identity directory")
}
}
handleCacheMisses.Inc()
Expand All @@ -198,10 +199,10 @@ func (d *RedisDirectory) ResolveHandle(ctx context.Context, h syntax.Handle) (sy
} else if entry.DID != nil {
return *entry.DID, nil
} else {
return "", fmt.Errorf("code flow error in redis identity directory")
return "", errors.New("code flow error in redis identity directory")
}
}
return "", fmt.Errorf("identity not found in cache after coalesce returned")
return "", errors.New("identity not found in cache after coalesce returned")
case <-ctx.Done():
return "", ctx.Err()
}
Expand All @@ -221,7 +222,7 @@ func (d *RedisDirectory) ResolveHandle(ctx context.Context, h syntax.Handle) (sy
if newEntry.DID != nil {
return *newEntry.DID, nil
}
return "", fmt.Errorf("unexpected control-flow error")
return "", errors.New("unexpected control-flow error")
}

func (d *RedisDirectory) updateDID(ctx context.Context, did syntax.DID) identityEntry {
Expand Down Expand Up @@ -302,7 +303,7 @@ func (d *RedisDirectory) LookupDIDWithCacheState(ctx context.Context, did syntax
if err == nil && !d.isIdentityStale(&entry) { // if no error...
return entry.Identity, false, entry.Err
}
return nil, false, fmt.Errorf("identity not found in cache after coalesce returned")
return nil, false, errors.New("identity not found in cache after coalesce returned")
case <-ctx.Done():
return nil, false, ctx.Err()
}
Expand All @@ -322,7 +323,7 @@ func (d *RedisDirectory) LookupDIDWithCacheState(ctx context.Context, did syntax
if newEntry.Identity != nil {
return newEntry.Identity, false, nil
}
return nil, false, fmt.Errorf("unexpected control-flow error")
return nil, false, errors.New("unexpected control-flow error")
}

func (d *RedisDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*identity.Identity, error) {
Expand Down Expand Up @@ -360,7 +361,7 @@ func (d *RedisDirectory) Lookup(ctx context.Context, a syntax.AtIdentifier) (*id
if err == nil { // if not an error, is a DID
return d.LookupDID(ctx, did)
}
return nil, fmt.Errorf("at-identifier neither a Handle nor a DID")
return nil, errors.New("at-identifier neither a Handle nor a DID")
}

func (d *RedisDirectory) Purge(ctx context.Context, a syntax.AtIdentifier) error {
Expand All @@ -381,5 +382,5 @@ func (d *RedisDirectory) Purge(ctx context.Context, a syntax.AtIdentifier) error
}
return err
}
return fmt.Errorf("at-identifier neither a Handle nor a DID")
return errors.New("at-identifier neither a Handle nor a DID")
}

0 comments on commit dc4176c

Please sign in to comment.