Skip to content

Commit

Permalink
fix(peers): If user is not connected, show error instead of segfaulting.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Jul 17, 2018
1 parent 21453de commit 80b1e3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (d *PeerRequests) List(p *PeerListParams, res *[]*config.ProfilePod) error
if d.cli != nil {
return d.cli.Call("PeerRequests.List", p, res)
}
if d.qriNode == nil {
return fmt.Errorf("error: not connected, run `qri connect` in another window")
}

r := d.qriNode.Repo
user, err := r.Profile()
Expand Down
13 changes: 13 additions & 0 deletions lib/peers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lib

import (
"strings"
"testing"

"github.com/qri-io/qri/config"
Expand All @@ -10,6 +11,18 @@ import (
testrepo "github.com/qri-io/qri/repo/test"
)

func TestPeerRequestsListNoConnection(t *testing.T) {
req := NewPeerRequests(nil, nil)
p := PeerListParams{}
got := []*config.ProfilePod{}
err := req.List(&p, &got)
if err == nil {
t.Errorf("error: req.List should have failed and returned an error")
} else if !strings.HasPrefix(err.Error(), "error: not connected") {
t.Errorf("error: unexpected error message: %s", err.Error())
}
}

func TestPeerRequestsList(t *testing.T) {
cases := []struct {
p *PeerListParams
Expand Down

0 comments on commit 80b1e3e

Please sign in to comment.