Skip to content

Commit

Permalink
nip17: fix nil pointer
Browse files Browse the repository at this point in the history
Fixes a nil pointer when the Publish succeeds.
In that case the err is nil, and calling .Error() on nil causes a nil
pointer exception.
Reproduced at: https://play.golang.com/p/ps8d82Qt9kO
  • Loading branch information
alessio-perugini authored and fiatjaf committed Jan 5, 2025
1 parent defc349 commit 967a08f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion nip17/nip17.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func PublishMessage(
}

err = r.Publish(ctx, event)
if strings.HasPrefix(err.Error(), "auth-required:") {
if err != nil && strings.HasPrefix(err.Error(), "auth-required:") {
authErr := r.Auth(ctx, func(ae *nostr.Event) error { return kr.SignEvent(ctx, ae) })
if authErr == nil {
err = r.Publish(ctx, event)
Expand Down

0 comments on commit 967a08f

Please sign in to comment.