From 8201e310a28df3b0d3902d1d8c70293c91747436 Mon Sep 17 00:00:00 2001 From: Matthias Hannig Date: Wed, 24 May 2017 11:41:19 +0200 Subject: [PATCH] handle missing data --- backend/sources/birdwatcher/parsers.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/sources/birdwatcher/parsers.go b/backend/sources/birdwatcher/parsers.go index 8b53337..616768f 100644 --- a/backend/sources/birdwatcher/parsers.go +++ b/backend/sources/birdwatcher/parsers.go @@ -3,6 +3,7 @@ package birdwatcher // Parsers and helpers import ( + "fmt" "sort" "strconv" "time" @@ -138,7 +139,11 @@ func parseNeighbours(bird ClientResponse, config Config) ([]api.Neighbour, error // Parse route bgp info func parseRouteBgpInfo(data interface{}) api.BgpInfo { - bgpData := data.(map[string]interface{}) + bgpData, ok := data.(map[string]interface{}) + if !ok { + // Info is missing + return api.BgpInfo{} + } asPath := parseIntList(bgpData["as_path"]) communities := parseBgpCommunities(bgpData["communities"]) @@ -196,7 +201,10 @@ func mustString(value interface{}, fallback string) string { // Assert list of strings func mustStringList(data interface{}) []string { list := []string{} - ldata := data.([]interface{}) + ldata, ok := data.([]interface{}) + if !ok { + return []string{} + } for _, e := range ldata { s, ok := e.(string) if ok { @@ -230,7 +238,7 @@ func parseRoutes(bird ClientResponse, config Config) ([]api.Route, error) { routes := api.Routes{} birdRoutes, ok := bird["routes"].([]interface{}) if !ok { - return routes, nil + return routes, fmt.Errorf("Routes response missing") } for _, data := range birdRoutes {