From 4115f733435c1f6d4a10cf71d0d058d6bc7858c6 Mon Sep 17 00:00:00 2001 From: Nan Deng Date: Wed, 2 Jul 2014 16:20:05 -0700 Subject: [PATCH] type check --- storage/influxdb/influxdb.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/storage/influxdb/influxdb.go b/storage/influxdb/influxdb.go index f665fd1c..1d42ef0d 100644 --- a/storage/influxdb/influxdb.go +++ b/storage/influxdb/influxdb.go @@ -193,8 +193,12 @@ func (self *influxdbStorage) valuesToContainerStats(columns []string, values []i stats.Timestamp, err = time.Parse(time.RFC3339Nano, str) } case col == colMachineName: - if v.(string) != self.machineName { - return nil, fmt.Errorf("different machine") + if m, ok := v.(string); ok { + if m != self.machineName { + return nil, fmt.Errorf("different machine") + } + } else { + return nil, fmt.Errorf("machine name field is not a string: %v", v) } // Cumulative Cpu Usage case col == colCpuCumulativeUsage: @@ -254,8 +258,12 @@ func (self *influxdbStorage) valuesToContainerSample(columns []string, values [] sample.Timestamp, err = time.Parse(time.RFC3339Nano, str) } case col == colMachineName: - if v.(string) != self.machineName { - return nil, fmt.Errorf("different machine") + if m, ok := v.(string); ok { + if m != self.machineName { + return nil, fmt.Errorf("different machine") + } + } else { + return nil, fmt.Errorf("machine name field is not a string: %v", v) } // Memory Usage case col == colMemoryUsage: