From f94bba4f40001a7e7069845e2aa1d6d95b4a5a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Mon, 30 Jul 2018 15:07:08 +0200 Subject: [PATCH] add more error checking and print to stderr (#7796) --- libbeat/generator/fields/fields.go | 10 ++++++++-- libbeat/scripts/cmd/global_fields/main.go | 6 ++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libbeat/generator/fields/fields.go b/libbeat/generator/fields/fields.go index 724338ab42bc..9449f55de907 100644 --- a/libbeat/generator/fields/fields.go +++ b/libbeat/generator/fields/fields.go @@ -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() } @@ -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() } diff --git a/libbeat/scripts/cmd/global_fields/main.go b/libbeat/scripts/cmd/global_fields/main.go index 22fbd8cb1bf9..238ce040b8b8 100644 --- a/libbeat/scripts/cmd/global_fields/main.go +++ b/libbeat/scripts/cmd/global_fields/main.go @@ -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 } @@ -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)) }