Skip to content

Commit

Permalink
Handle case where pk can't be resolved, better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lxcode committed Dec 17, 2024
1 parent 8edd8dc commit 1b9bfcf
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions pkg/hydrator/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,25 @@ func (h *Hydrator) lookupPost(atUrl string) (post *bsky.FeedDefs_PostView, err e
return
}

func (h *Hydrator) flattenIdentity(identity *atpidentity.Identity) (result map[string]interface{}) {
func (h *Hydrator) flattenIdentity(identity *atpidentity.Identity) (result map[string]interface{}, err error) {
if identity == nil {
return nil
return nil, fmt.Errorf("identity is nil")
}

result = make(map[string]interface{})

result["DID"] = identity.Handle.String()
result["Handle"] = identity.Handle

var pk crypto.PublicKey
pk, _ = identity.PublicKey()
if err != nil {
log.Warnf("Failed to get public key for actor: %s, %s", identity.Handle, err)
} else {

result["DIDKey"] = pk.DIDKey()
}

result["DID"] = identity.Handle.String()
result["Handle"] = identity.Handle
result["DIDKey"] = pk.DIDKey()
result["PDS"] = identity.PDSEndpoint()

return
Expand Down Expand Up @@ -531,13 +537,13 @@ func (h *Hydrator) Hydrate(val interface{}, actorDid string) (result map[string]
// Resolve full identity and profile information for the actor
identity, err := h.LookupIdentity(actorDid)
if err != nil {
log.Warnf("Failed to get profile for actor: %s", actorDid)
log.Warnf("Failed to lookup identity for actor %s: %s", actorDid, err)
identity = nil
}

profile, err := h.lookupProfileFromIdentity(identity)
if err != nil {
log.Warnf("Failed to get profile for actor: %s", actorDid)
log.Warnf("Failed to lookup profile for actor %s: %s", actorDid, err)
profile = nil
}

Expand All @@ -550,7 +556,12 @@ func (h *Hydrator) Hydrate(val interface{}, actorDid string) (result map[string]
full["_ActorDid"] = actorDid
full["_ActorIdentity"] = identity
full["_ActorProfile"] = profile
projection["Actor"] = h.flattenIdentity(identity)
flat, err := h.flattenIdentity(identity)
if err != nil {
log.Warnf("Failed to flatten identity %s: %s", actorDid, err)
flat = nil
}
projection["Actor"] = flat

// Depending on the type, add additional information
switch val := val.(type) {
Expand Down

0 comments on commit 1b9bfcf

Please sign in to comment.