Skip to content

Commit

Permalink
fix(list): Listing a non-existant profile should not crash
Browse files Browse the repository at this point in the history
Before, running `qri list not_found` would try to deref a nil error value,
leading to a crash. Instead, check if the returned profile pointer is
null and print an appropriate error.
  • Loading branch information
dustmop committed Jan 14, 2019
1 parent 61ff88c commit e00d516
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion actions/list_datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ func ListDatasets(node *p2p.QriNode, ds *repo.DatasetRef, limit, offset int, RPC
pro = p
}
}
if pro == nil {
if err != nil {
return nil, fmt.Errorf("couldn't find profile: %s", err.Error())
}
if pro == nil {
return nil, fmt.Errorf("profile not found: \"%s\"", ds.Peername)
}

if len(pro.PeerIDs) == 0 {
return nil, fmt.Errorf("couldn't find a peer address for profile: %s", pro.ID)
Expand Down
14 changes: 14 additions & 0 deletions actions/list_datasets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ func TestListDatasets(t *testing.T) {
t.Error("expected one dataset response")
}
}

func TestListDatasetsNotFound(t *testing.T) {
node := newTestNode(t)
addCitiesDataset(t, node)

_, err := ListDatasets(node, &repo.DatasetRef{Peername: "not_found"}, 1, 0, false, false)
if err == nil {
t.Error("expected to get error")
}
expect := "profile not found: \"not_found\""
if expect != err.Error() {
t.Errorf("expected error \"%s\", got \"%s\"", expect, err.Error())
}
}

0 comments on commit e00d516

Please sign in to comment.