Skip to content

Commit

Permalink
Merge pull request vitessio#2218 from michael-berlin/fix_vtctld_nil_d…
Browse files Browse the repository at this point in the history
…ereference

vtctld: Do not access embedded proto if err != nil.
  • Loading branch information
michael-berlin authored Nov 5, 2016
2 parents 82cb07d + cef4265 commit ab58e11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions go/vt/vtctld/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ func initAPI(ctx context.Context, ts topo.Server, actions *ActionRepository, rea
}
// Get the keyspace record.
k, err := ts.GetKeyspace(ctx, keyspace)
if err != nil {
return nil, err
}
// Pass the embedded proto directly or jsonpb will panic.
return k.Keyspace, err
// Perform an action on a keyspace.
Expand Down Expand Up @@ -220,6 +223,9 @@ func initAPI(ctx context.Context, ts topo.Server, actions *ActionRepository, rea

// Get the shard record.
si, err := ts.GetShard(ctx, keyspace, shard)
if err != nil {
return nil, err
}
// Pass the embedded proto directly or jsonpb will panic.
return si.Shard, err
})
Expand Down Expand Up @@ -336,6 +342,9 @@ func initAPI(ctx context.Context, ts topo.Server, actions *ActionRepository, rea

// Get the tablet record.
t, err := ts.GetTablet(ctx, tabletAlias)
if err != nil {
return nil, err
}
// Pass the embedded proto directly or jsonpb will panic.
return t.Tablet, err
})
Expand Down
5 changes: 4 additions & 1 deletion go/vt/vtctld/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestAPI(t *testing.T) {
"sharding_column_name": "shardcol",
"sharding_column_type": 0
}`},
{"GET", "keyspaces/nonexistent", "", "404 page not found"},
{"POST", "keyspaces/ks1?action=TestKeyspaceAction", "", `{
"Name": "TestKeyspaceAction",
"Parameters": "ks1",
Expand All @@ -120,6 +121,7 @@ func TestAPI(t *testing.T) {
"key_range": {"end":"gA=="},
"cells": ["cell1", "cell2"]
}`},
{"GET", "shards/ks1/-DEAD", "", "404 page not found"},
{"POST", "shards/ks1/-80?action=TestShardAction", "", `{
"Name": "TestShardAction",
"Parameters": "ks1/-80",
Expand Down Expand Up @@ -149,6 +151,7 @@ func TestAPI(t *testing.T) {
"type": 2,
"db_name_override": ""
}`},
{"GET", "tablets/nonexistent-999", "", "404 page not found"},
{"POST", "tablets/cell1-100?action=TestTabletAction", "", `{
"Name": "TestTabletAction",
"Parameters": "cell1-0000000100",
Expand All @@ -169,7 +172,7 @@ func TestAPI(t *testing.T) {
]`},
{"GET", "tablet_statuses/?keyspace=ks1&cell=all&type=all&metric=lag", "", `[
{
"Data":[[-1,400],[-1,300],[200,-1],[100,-1]],
"Data":[[-1,400],[-1,300],[200,-1],[100,-1]],
"Aliases":[[null,{"cell":"cell2","uid":400}],[null,{"cell":"cell2","uid":300}],[{"cell":"cell1","uid":200},null],[{"cell":"cell1","uid":100},null]],
"KeyspaceLabel":{"Name":"ks1","Rowspan":4},
"CellAndTypeLabels":[
Expand Down

0 comments on commit ab58e11

Please sign in to comment.