-
Notifications
You must be signed in to change notification settings - Fork 133
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
base: main
Are you sure you want to change the base?
Misc. fixes #852
Changes from all commits
e3f0652
37f50f5
c4befdb
4c9c614
d90abdf
09c3c35
9f8d020
d16ddc8
9ab4495
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)") | ||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required after any |
||
|
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
for f := range m { | ||
out = append(out, f) | ||
} | ||
s.Data[key] = out | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant
return
.