Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. fixes #852

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions api/plc.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ func (s *PLCServer) GetDocument(ctx context.Context, didstr string) (*did.Docume
return &doc, nil
}

func (s *PLCServer) FlushCacheFor(did string) {
return
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant return.

}
func (s *PLCServer) FlushCacheFor(did string) {}

type CreateOp struct {
Type string `json:"type" cborgen:"type"`
Expand Down
6 changes: 4 additions & 2 deletions atproto/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ func extractBlobsAtom(atom any) []Blob {
out = append(out, v)
case []any:
for _, el := range v {
out = append(out, extractBlobsAtom(el)...)
down := extractBlobsAtom(el)
out = append(out, down...)
}
case map[string]any:
for _, val := range v {
out = append(out, extractBlobsAtom(val)...)
down := extractBlobsAtom(val)
out = append(out, down...)
}
default:
}
Expand Down
11 changes: 5 additions & 6 deletions atproto/identity/cmd/atp-id/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package main

import (
"context"
"encoding/json"
"fmt"
"log/slog"
"os"

"github.com/urfave/cli/v2"

"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/syntax"

"github.com/urfave/cli/v2"
)

func main() {
Expand Down Expand Up @@ -44,7 +43,7 @@ func main() {
}

func runLookup(cctx *cli.Context) error {
ctx := context.Background()
ctx := cctx.Context
s := cctx.Args().First()
if s == "" {
return fmt.Errorf("need to provide identifier as an argument")
Expand All @@ -66,7 +65,7 @@ func runLookup(cctx *cli.Context) error {
}

func runResolveHandle(cctx *cli.Context) error {
ctx := context.Background()
ctx := cctx.Context
s := cctx.Args().First()
if s == "" {
return fmt.Errorf("need to provide handle as an argument")
Expand All @@ -88,7 +87,7 @@ func runResolveHandle(cctx *cli.Context) error {
}

func runResolveDID(cctx *cli.Context) error {
ctx := context.Background()
ctx := cctx.Context
s := cctx.Args().First()
if s == "" {
fmt.Println("need to provide DID as an argument")
Expand Down
2 changes: 1 addition & 1 deletion atproto/identity/mock_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ func TestMockDirectory(t *testing.T) {

_, err = c.LookupHandle(ctx, syntax.HandleInvalid)
assert.ErrorIs(err, ErrHandleNotFound)
out, err = c.LookupDID(ctx, syntax.DID("did:plc:abc999"))
_, err = c.LookupDID(ctx, syntax.DID("did:plc:abc999"))
assert.ErrorIs(err, ErrDIDNotFound)
}
25 changes: 16 additions & 9 deletions atproto/lexicon/cmd/lextool/net.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package main

import (
"context"
"fmt"
"io"
"log/slog"
"net/http"

"github.com/bobg/errors"
"github.com/urfave/cli/v2"

"github.com/bluesky-social/indigo/atproto/data"
"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/lexicon"
"github.com/bluesky-social/indigo/atproto/syntax"

"github.com/urfave/cli/v2"
)

func runValidateRecord(cctx *cli.Context) error {
ctx := context.Background()
ctx := cctx.Context
args := cctx.Args().Slice()
if len(args) != 2 {
return fmt.Errorf("expected two args (catalog path and AT-URI)")
Expand All @@ -29,12 +29,12 @@ func runValidateRecord(cctx *cli.Context) error {
cat := lexicon.NewBaseCatalog()
err := cat.LoadDirectory(p)
if err != nil {
return err
return errors.Wrap(err, "in LoadDirectory")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially when a function has multiple error return sites, it's useful to wrap them to know which site did the returning.

}

aturi, err := syntax.ParseATURI(args[1])
if err != nil {
return err
return errors.Wrap(err, "in ParseATURI")
}
if aturi.RecordKey() == "" {
return fmt.Errorf("need a full, not partial, AT-URI: %s", aturi)
Expand All @@ -54,17 +54,24 @@ func runValidateRecord(cctx *cli.Context) error {
pdsURL, ident.DID, aturi.Collection(), aturi.RecordKey())
resp, err := http.Get(url)
if err != nil {
return err
return errors.Wrap(err, "in http.Get")
}
defer resp.Body.Close()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required after any http.Get (and a few other operations).


if resp.StatusCode != http.StatusOK {
return fmt.Errorf("fetch failed")
}

respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
return errors.Wrap(err, "in ReadAll")
}

body, err := data.UnmarshalJSON(respBytes)
if err != nil {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error was not being checked.

return errors.Wrap(err, "in UnmarshalJSON")
}

record, ok := body["value"].(map[string]any)
if !ok {
return fmt.Errorf("fetched record was not an object")
Expand All @@ -73,7 +80,7 @@ func runValidateRecord(cctx *cli.Context) error {
slog.Info("validating", "did", ident.DID.String(), "collection", aturi.Collection().String(), "rkey", aturi.RecordKey().String())
err = lexicon.ValidateRecord(&cat, record, aturi.Collection().String(), lexicon.LenientMode)
if err != nil {
return err
return errors.Wrap(err, "in ValidateRecord")
}
fmt.Println("success!")
return nil
Expand Down
1 change: 0 additions & 1 deletion atproto/lexicon/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func (s *SchemaDef) SetBase(base string) {
}
s.Inner = v
}
return
}

func (s SchemaDef) MarshalJSON() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion atproto/lexicon/lexicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func validateArray(cat Catalog, s SchemaArray, arr []any, flags ValidateFlags) e
}

func validateUnion(cat Catalog, s SchemaUnion, d any, flags ValidateFlags) error {
closed := s.Closed != nil && *s.Closed == true
closed := s.Closed != nil && *s.Closed

obj, ok := d.(map[string]any)
if !ok {
Expand Down
1 change: 0 additions & 1 deletion automod/consumer/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ func (fc *FirehoseConsumer) HandleRepoCommit(ctx context.Context, evt *comatprot
action = automod.UpdateOp
default:
logger.Error("impossible event kind", "kind", ek)
break
}
recCID := syntax.CID(op.Cid.String())
op := automod.RecordOp{
Expand Down
6 changes: 3 additions & 3 deletions automod/engine/fetch_account_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (e *Engine) GetAccountMeta(ctx context.Context, ident *identity.Identity) (
var labels []string
var negLabels []string
for _, lbl := range pv.Labels {
if lbl.Neg != nil && *lbl.Neg == true {
if lbl.Neg != nil && *lbl.Neg {
negLabels = append(negLabels, lbl.Val)
} else {
labels = append(labels, lbl.Val)
Expand Down Expand Up @@ -130,10 +130,10 @@ func (e *Engine) GetAccountMeta(ctx context.Context, ident *identity.Identity) (
am.Deactivated = true
}
if rd.Moderation != nil && rd.Moderation.SubjectStatus != nil {
if rd.Moderation.SubjectStatus.Takendown != nil && *rd.Moderation.SubjectStatus.Takendown == true {
if rd.Moderation.SubjectStatus.Takendown != nil && *rd.Moderation.SubjectStatus.Takendown {
am.Takendown = true
}
if rd.Moderation.SubjectStatus.Appealed != nil && *rd.Moderation.SubjectStatus.Appealed == true {
if rd.Moderation.SubjectStatus.Appealed != nil && *rd.Moderation.SubjectStatus.Appealed {
ap.Appealed = true
}
ap.AccountTags = dedupeStrings(rd.Moderation.SubjectStatus.Tags)
Expand Down
2 changes: 1 addition & 1 deletion automod/engine/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (eng *Engine) persistRecordModActions(c *RecordContext) error {
var existingLabels []string
var negLabels []string
for _, lbl := range rv.Labels {
if lbl.Neg != nil && *lbl.Neg == true {
if lbl.Neg != nil && *lbl.Neg {
negLabels = append(negLabels, lbl.Val)
} else {
existingLabels = append(existingLabels, lbl.Val)
Expand Down
9 changes: 3 additions & 6 deletions automod/flagstore/flagstore_mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ func (s MemFlagStore) Get(ctx context.Context, key string) ([]string, error) {
}

func (s MemFlagStore) Add(ctx context.Context, key string, flags []string) error {
v, ok := s.Data[key]
if !ok {
v = []string{}
}
v := s.Data[key]
v = append(v, flags...)
v = dedupeStrings(v)
s.Data[key] = v
Expand All @@ -49,8 +46,8 @@ func (s MemFlagStore) Remove(ctx context.Context, key string, flags []string) er
for _, f := range flags {
delete(m, f)
}
out := []string{}
for f, _ := range m {
var out []string
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost always the better way to initialize a slice. This sets it to nil - with no "slice header" - which is exactly equivalent to []string{} (which does have a slice header) in almost all contexts, such as len and append and for range, etc.

for f := range m {
out = append(out, f)
}
s.Data[key] = out
Expand Down
5 changes: 1 addition & 4 deletions automod/helpers/bsky.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ func ParentOrRootIsFollower(c *automod.RecordContext, post *appbsky.FeedPost) bo
}

rel = c.GetAccountRelationship(rootDID)
if rel.FollowedBy {
return true
}
return false
return rel.FollowedBy
}

func PostParentOrRootIsDid(post *appbsky.FeedPost, did string) bool {
Expand Down
7 changes: 3 additions & 4 deletions automod/keyword/cmd/kw-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package main

import (
"bufio"
"context"
"fmt"
"log/slog"
"os"

"github.com/urfave/cli/v2"

"github.com/bluesky-social/indigo/automod/keyword"
"github.com/bluesky-social/indigo/automod/setstore"

"github.com/urfave/cli/v2"
)

func main() {
Expand Down Expand Up @@ -64,7 +63,7 @@ func runFuzzy(cctx *cli.Context) error {
}

func runTokens(cctx *cli.Context) error {
ctx := context.Background()
ctx := cctx.Context
sets := setstore.NewMemSetStore()
if err := sets.LoadFromFileJSON(cctx.String("json-set-file")); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion automod/keyword/tokenize.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

var (
puncChars = regexp.MustCompile(`[[:punct:]]+`)
nonTokenChars = regexp.MustCompile(`[^\pL\pN\s]+`)
nonTokenCharsSkipCensorChars = regexp.MustCompile(`[^\pL\pN\s#*_-]`)
)
Expand Down
Loading