Skip to content

Commit

Permalink
add more error checking and print to stderr (#7796)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch authored and ruflin committed Jul 30, 2018
1 parent f771f2d commit f94bba4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 8 additions & 2 deletions libbeat/generator/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func writeGeneratedFieldsYml(beatPath string, fieldFiles []*YmlFile, output stri

if output == "-" {
fw := bufio.NewWriter(os.Stdout)
fw.Write(data)
_, err = fw.Write(data)
if err != nil {
return err
}
return fw.Flush()
}

Expand All @@ -93,7 +96,10 @@ func writeGeneratedFieldsYml(beatPath string, fieldFiles []*YmlFile, output stri
defer f.Close()

fw := bufio.NewWriter(f)
fw.Write(data)
_, err = fw.Write(data)
if err != nil {
return err
}
return fw.Flush()
}

Expand Down
6 changes: 2 additions & 4 deletions libbeat/scripts/cmd/global_fields/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
// it's not a problem because all of them has unique fields.yml files somewhere.
if len(beatFieldsPaths) == 0 && os.SameFile(esBeatsInfo, beatInfo) {
if output != "-" {
fmt.Println("No field files to collect")
fmt.Fprintln(os.Stderr, "No field files to collect")
}
return
}
Expand All @@ -95,7 +95,5 @@ func main() {
os.Exit(3)
}

if output != "-" {
fmt.Printf("Generated fields.yml for %s\n", name)
}
fmt.Fprintf(os.Stderr, "Generated fields.yml for %s to %s\n", name, filepath.Join(beatPath, output))
}

0 comments on commit f94bba4

Please sign in to comment.