From e77e87215dadb100d4bab1706ac7d72ecb68a8f0 Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Tue, 22 Feb 2022 13:20:34 -0500 Subject: [PATCH] Improve registry error message If the registry file is invalid for some reason the error can be ambiguous given that the config file is also in YAML. So give the errors more context. This is an example of the ambiguous error: Exiting: yaml: control characters are not allowed --- CHANGELOG.next.asciidoc | 2 ++ winlogbeat/beater/winlogbeat.go | 2 +- winlogbeat/checkpoint/checkpoint.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index a0aaea48833a..8ad6feff7387 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -143,6 +143,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...main[Check the HEAD dif *Winlogbeat* +- Improve the error message when the registry file content is invalid. {pull}30543[30543] + *Elastic Log Driver* diff --git a/winlogbeat/beater/winlogbeat.go b/winlogbeat/beater/winlogbeat.go index ec7ebf90ef6f..82a3012715d1 100644 --- a/winlogbeat/beater/winlogbeat.go +++ b/winlogbeat/beater/winlogbeat.go @@ -126,7 +126,7 @@ func (eb *Winlogbeat) setup(b *beat.Beat) error { var err error eb.checkpoint, err = checkpoint.NewCheckpoint(config.RegistryFile, config.RegistryFlush) if err != nil { - return err + return fmt.Errorf("failed to initialize checkpoint registry: %w", err) } eb.pipeline = b.Publisher diff --git a/winlogbeat/checkpoint/checkpoint.go b/winlogbeat/checkpoint/checkpoint.go index a93b29abed1f..3931b67920d8 100644 --- a/winlogbeat/checkpoint/checkpoint.go +++ b/winlogbeat/checkpoint/checkpoint.go @@ -264,7 +264,7 @@ func (c *Checkpoint) read() (*PersistedState, error) { ps := &PersistedState{} err = yaml.Unmarshal(contents, ps) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to read persisted state: %w", err) } return ps, nil