use AddError everywhere (#2372)

This commit is contained in:
Patrick Hemmer
2017-04-24 14:13:26 -04:00
committed by Daniel Nelson
parent 801f6cb8a0
commit 06baf7cf78
95 changed files with 341 additions and 531 deletions

View File

@@ -48,7 +48,6 @@ func (_ *FileStat) Description() string {
func (_ *FileStat) SampleConfig() string { return sampleConfig }
func (f *FileStat) Gather(acc telegraf.Accumulator) error {
var errS string
var err error
for _, filepath := range f.Files {
@@ -56,7 +55,7 @@ func (f *FileStat) Gather(acc telegraf.Accumulator) error {
g, ok := f.globs[filepath]
if !ok {
if g, err = globpath.Compile(filepath); err != nil {
errS += err.Error() + " "
acc.AddError(err)
continue
}
f.globs[filepath] = g
@@ -92,7 +91,7 @@ func (f *FileStat) Gather(acc telegraf.Accumulator) error {
if f.Md5 {
md5, err := getMd5(fileName)
if err != nil {
errS += err.Error() + " "
acc.AddError(err)
} else {
fields["md5_sum"] = md5
}
@@ -102,9 +101,6 @@ func (f *FileStat) Gather(acc telegraf.Accumulator) error {
}
}
if errS != "" {
return fmt.Errorf(errS)
}
return nil
}

View File

@@ -19,7 +19,7 @@ func TestGatherNoMd5(t *testing.T) {
}
acc := testutil.Accumulator{}
fs.Gather(&acc)
acc.GatherError(fs.Gather)
tags1 := map[string]string{
"file": dir + "log1.log",
@@ -59,7 +59,7 @@ func TestGatherExplicitFiles(t *testing.T) {
}
acc := testutil.Accumulator{}
fs.Gather(&acc)
acc.GatherError(fs.Gather)
tags1 := map[string]string{
"file": dir + "log1.log",
@@ -99,7 +99,7 @@ func TestGatherGlob(t *testing.T) {
}
acc := testutil.Accumulator{}
fs.Gather(&acc)
acc.GatherError(fs.Gather)
tags1 := map[string]string{
"file": dir + "log1.log",
@@ -131,7 +131,7 @@ func TestGatherSuperAsterisk(t *testing.T) {
}
acc := testutil.Accumulator{}
fs.Gather(&acc)
acc.GatherError(fs.Gather)
tags1 := map[string]string{
"file": dir + "log1.log",