Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
asymmetric committed Jan 14, 2025
1 parent 61734b7 commit 9474a2b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 10 additions & 4 deletions message_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,16 @@ func checkIfSubExists(attr_path, roomid string) (exists bool, err error) {
// 1. uses jquery to parse the JSON blob
// 2. finds list of packages maintained by handle
// 3. uses SQL to intersect with list of tracked packages
func findPackagesForHandle(jsobj map[string]any, handle string) []string {
func findPackagesForHandle(jsobj map[string]any, handle string) ([]string, error) {
query, err := gojq.Parse(fmt.Sprintf(`.packages|to_entries[]|select(.value.meta.maintainers[]?|.github|match("^%s$"))|.key`, handle))
if err != nil {
panic(err)
slog.Error("gojq parse", "error", err)

return nil, err
}

slog.Debug("gojq query", "query", query)

// list of maintained packages
var mps []string
iter := query.Run(jsobj)
Expand All @@ -270,7 +274,9 @@ func findPackagesForHandle(jsobj map[string]any, handle string) []string {
if err, ok := err.(*gojq.HaltError); ok && err.Value() == nil {
break
}
panic(err)
slog.Error("gojq run", "error", err)

return nil, err
}
mps = append(mps, v.(string))
}
Expand Down Expand Up @@ -302,7 +308,7 @@ func findPackagesForHandle(jsobj map[string]any, handle string) []string {
panic(err)
}

return aps
return aps, nil
}

// Fetches the packages.json.br, unpacks it and returns it as serialized JSON.
Expand Down
9 changes: 8 additions & 1 deletion message_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,14 @@ func TestFollow(t *testing.T) {

var exists bool
var err error
for _, p := range findPackagesForHandle(h.packagesJSONFetcher(), "asymmetric") {
data, err := findPackagesForHandle(h.packagesJSONFetcher(), "asymmetric")
if err != nil {
if _, err = h.sender("There was a problem processing your request, sorry.", evt.RoomID); err != nil {
slog.Error(err.Error())
}
}

for _, p := range data {
exists, err = checkIfSubExists(p, evt.RoomID.String())
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
default = null;
};
debug = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
type = lib.types.bool;
default = false;
};
};
};
Expand Down

0 comments on commit 9474a2b

Please sign in to comment.