diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index a38beab5118..00c12ad2cb3 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -56,3 +56,4 @@ - Do not require unnecessary configuration {pull}18003[18003] - Use nested objects so fleet can handle metadata correctly {pull}18234[18234] - Enable debug log level for Metricbeat and Filebeat when run under the Elastic Agent. {pull}17935[17935] +- More clear output of inspect command {pull}18405[18405] diff --git a/x-pack/elastic-agent/pkg/agent/application/introspect_config_cmd.go b/x-pack/elastic-agent/pkg/agent/application/introspect_config_cmd.go index f5ab634b84d..bb5d25c2c35 100644 --- a/x-pack/elastic-agent/pkg/agent/application/introspect_config_cmd.go +++ b/x-pack/elastic-agent/pkg/agent/application/introspect_config_cmd.go @@ -53,7 +53,7 @@ func (c *IntrospectConfigCmd) introspectConfig() error { if err != nil { return err } else if fleetConfig == nil { - return errors.New("no fleet config retrieved yet") + return fmt.Errorf("no fleet config retrieved yet") } return printMapStringConfig(fleetConfig) diff --git a/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go b/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go index 26eb424fe97..cb7c185fbd5 100644 --- a/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go +++ b/x-pack/elastic-agent/pkg/agent/application/introspect_output_cmd.go @@ -13,7 +13,6 @@ import ( "github.com/urso/ecslog/backend/layout" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/filters" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/program" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" @@ -69,7 +68,7 @@ func (c *IntrospectOutputCmd) introspectOutputs() error { if err != nil { return err } else if fleetConfig == nil { - return errors.New("no fleet config retrieved yet") + return fmt.Errorf("no fleet config retrieved yet") } return listOutputsFromMap(l, fleetConfig) @@ -122,7 +121,7 @@ func (c *IntrospectOutputCmd) introspectOutput() error { if err != nil { return err } else if fleetConfig == nil { - return errors.New("no fleet config retrieved yet") + return fmt.Errorf("no fleet config retrieved yet") } return printOutputFromMap(l, c.output, c.program, fleetConfig) @@ -153,16 +152,16 @@ func printOutputFromConfig(log *logger.Logger, output, programName string, cfg * } if !programFound { - fmt.Printf("program '%s' is not recognized within output '%s', try running `elastic-agent introspect output` to find available outputs.\n", + return fmt.Errorf("program '%s' is not recognized within output '%s', try running `elastic-agent introspect output` to find available outputs", programName, output) } + return nil } - fmt.Printf("output '%s' is not recognized, try running `elastic-agent introspect output` to find available outputs.\n", output) + return fmt.Errorf("output '%s' is not recognized, try running `elastic-agent introspect output` to find available outputs", output) - return nil } func printOutputFromMap(log *logger.Logger, output, programName string, cfg map[string]interface{}) error { diff --git a/x-pack/elastic-agent/pkg/agent/errors/error.go b/x-pack/elastic-agent/pkg/agent/errors/error.go index c972ed1f032..c3c1d6a5ddb 100644 --- a/x-pack/elastic-agent/pkg/agent/errors/error.go +++ b/x-pack/elastic-agent/pkg/agent/errors/error.go @@ -27,6 +27,11 @@ type agentError struct { meta map[string]interface{} } +// Unwrap returns nested error. +func (e agentError) Unwrap() error { + return e.err +} + // Error returns a string consisting of a message and originating error. func (e agentError) Error() string { if e.msg != "" {