Skip to content

Commit

Permalink
Removing obsolete errors package (#35825)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitkanfer authored Jun 21, 2023
1 parent 00ed225 commit 3325ba1
Show file tree
Hide file tree
Showing 61 changed files with 234 additions and 259 deletions.
10 changes: 5 additions & 5 deletions filebeat/cmd/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package cmd

import (
"errors"
"fmt"
"strings"

"github.com/pkg/errors"

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/cfgfile"
"github.com/elastic/beats/v7/libbeat/cmd"
Expand All @@ -32,16 +32,16 @@ func buildModulesManager(beat *beat.Beat) (cmd.ModulesManager, error) {

glob, err := config.String("config.modules.path", -1)
if err != nil {
return nil, errors.Errorf("modules management requires 'filebeat.config.modules.path' setting")
return nil, errors.New("modules management requires 'filebeat.config.modules.path' setting")
}

if !strings.HasSuffix(glob, "*.yml") {
return nil, errors.Errorf("wrong settings for config.modules.path, it is expected to end with *.yml. Got: %s", glob)
return nil, fmt.Errorf("wrong settings for config.modules.path, it is expected to end with *.yml. Got: %s", glob)
}

modulesManager, err := cfgfile.NewGlobManager(glob, ".yml", ".disabled")
if err != nil {
return nil, errors.Wrap(err, "initialization error")
return nil, fmt.Errorf("initialization error: %w", err)
}
return modulesManager, nil
}
9 changes: 4 additions & 5 deletions filebeat/fileset/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ package fileset

import (
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/pkg/errors"

"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/version"
)
Expand Down Expand Up @@ -242,14 +241,14 @@ nextProcessor:
for i, obj := range processors {
processor, err := NewProcessor(obj)
if err != nil {
return errors.Wrapf(err, "cannot parse processor in section '%s' index %d body=%+v", section, i, obj)
return fmt.Errorf("cannot parse processor in section '%s' index %d body=%+v: %w", section, i, obj, err)
}

// Adapt any on_failure processors for this processor.
prevOnFailure, _ := processor.GetList("on_failure")
if err = adaptProcessorsForCompatibility(esVersion, processor.Config(), "on_failure", true,
log.With("parent_processor_type", processor.Name(), "parent_processor_index", i)); err != nil {
return errors.Wrapf(err, "cannot parse on_failure for processor in section '%s' index %d body=%+v", section, i, obj)
return fmt.Errorf("cannot parse on_failure for processor in section '%s' index %d body=%+v: %w", section, i, obj, err)
}
if onFailure, _ := processor.GetList("on_failure"); len(prevOnFailure) > 0 && len(onFailure) == 0 {
processor.Delete("on_failure")
Expand All @@ -260,7 +259,7 @@ nextProcessor:
processor.Set("processor", []interface{}{inner})
if err = adaptProcessorsForCompatibility(esVersion, processor.Config(), "processor", false,
log.With("parent_processor_type", processor.Name(), "parent_processor_index", i)); err != nil {
return errors.Wrapf(err, "cannot parse inner processor for foreach in section '%s' index %d", section, i)
return fmt.Errorf("cannot parse inner processor for foreach in section '%s' index %d: %w", section, i, err)
}
newList, _ := processor.GetList("processor")
switch len(newList) {
Expand Down
41 changes: 20 additions & 21 deletions filebeat/fileset/fileset.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (

"github.com/elastic/go-ucfg"

errw "github.com/pkg/errors"
"gopkg.in/yaml.v2"

"github.com/elastic/beats/v7/libbeat/beat"
Expand Down Expand Up @@ -219,7 +218,7 @@ func (fs *Fileset) turnOffElasticsearchVars(vars map[string]interface{}, esVersi
if ok {
minVersion, err := version.New(minESVersion["version"].(string))
if err != nil {
return vars, fmt.Errorf("Error parsing version %s: %v", minESVersion["version"].(string), err)
return vars, fmt.Errorf("Error parsing version %s: %w", minESVersion["version"].(string), err)
}

logp.Debug("fileset", "Comparing ES version %s with requirement of %s", esVersion.String(), minVersion)
Expand Down Expand Up @@ -270,13 +269,13 @@ func ApplyTemplate(vars map[string]interface{}, templateString string, specialDe

tplFunctions, err := getTemplateFunctions(vars)
if err != nil {
return "", errw.Wrap(err, "error fetching template functions")
return "", fmt.Errorf("error fetching template functions: %w", err)
}
tpl = tpl.Funcs(tplFunctions)

tpl, err = tpl.Parse(templateString)
if err != nil {
return "", fmt.Errorf("Error parsing template %s: %v", templateString, err)
return "", fmt.Errorf("Error parsing template %s: %w", templateString, err)
}
buf := bytes.NewBufferString("")
err = tpl.Execute(buf, vars)
Expand Down Expand Up @@ -325,7 +324,7 @@ func getTemplateFunctions(vars map[string]interface{}) (template.FuncMap, error)
func (fs *Fileset) getBuiltinVars(info beat.Info) (map[string]interface{}, error) {
host, err := os.Hostname()
if err != nil || len(host) == 0 {
return nil, fmt.Errorf("Error getting the hostname: %v", err)
return nil, fmt.Errorf("Error getting the hostname: %w", err)
}
split := strings.SplitN(host, ".", 2)
hostname := split[0]
Expand All @@ -347,21 +346,21 @@ func (fs *Fileset) getBuiltinVars(info beat.Info) (map[string]interface{}, error
func (fs *Fileset) getInputConfig() (*conf.C, error) {
path, err := ApplyTemplate(fs.vars, fs.manifest.Input, false)
if err != nil {
return nil, fmt.Errorf("Error expanding vars on the input path: %v", err)
return nil, fmt.Errorf("Error expanding vars on the input path: %w", err)
}
contents, err := ioutil.ReadFile(filepath.Join(fs.modulePath, fs.name, path))
if err != nil {
return nil, fmt.Errorf("Error reading input file %s: %v", path, err)
return nil, fmt.Errorf("Error reading input file %s: %w", path, err)
}

yaml, err := ApplyTemplate(fs.vars, string(contents), false)
if err != nil {
return nil, fmt.Errorf("Error interpreting the template of the input: %v", err)
return nil, fmt.Errorf("Error interpreting the template of the input: %w", err)
}

cfg, err := conf.NewConfigWithYAML([]byte(yaml), "")
if err != nil {
return nil, fmt.Errorf("Error reading input config: %v", err)
return nil, fmt.Errorf("Error reading input config: %w", err)
}

cfg, err = mergePathDefaults(cfg)
Expand All @@ -373,11 +372,11 @@ func (fs *Fileset) getInputConfig() (*conf.C, error) {
if len(fs.fcfg.Input) > 0 {
overrides, err := conf.NewConfigFrom(fs.fcfg.Input)
if err != nil {
return nil, fmt.Errorf("Error creating config from input overrides: %v", err)
return nil, fmt.Errorf("Error creating config from input overrides: %w", err)
}
cfg, err = conf.MergeConfigsWithOptions([]*conf.C{cfg, overrides}, ucfg.FieldReplaceValues("**.paths"), ucfg.FieldAppendValues("**.processors"))
if err != nil {
return nil, fmt.Errorf("Error applying config overrides: %v", err)
return nil, fmt.Errorf("Error applying config overrides: %w", err)
}
}

Expand All @@ -388,18 +387,18 @@ func (fs *Fileset) getInputConfig() (*conf.C, error) {
rootPipelineID = fs.pipelineIDs[0]
}
if err := cfg.SetString(pipelineField, -1, rootPipelineID); err != nil {
return nil, errw.Wrap(err, "error setting the fileset pipeline ID in config")
return nil, fmt.Errorf("error setting the fileset pipeline ID in config: %w", err)
}
}

// force our the module/fileset name
err = cfg.SetString("_module_name", -1, fs.mname)
if err != nil {
return nil, fmt.Errorf("Error setting the _module_name cfg in the input config: %v", err)
return nil, fmt.Errorf("Error setting the _module_name cfg in the input config: %w", err)
}
err = cfg.SetString("_fileset_name", -1, fs.name)
if err != nil {
return nil, fmt.Errorf("Error setting the _fileset_name cfg in the input config: %v", err)
return nil, fmt.Errorf("Error setting the _fileset_name cfg in the input config: %w", err)
}

common.PrintConfigDebugf(cfg, "Merged input config for fileset %s/%s", fs.mname, fs.name)
Expand All @@ -413,7 +412,7 @@ func (fs *Fileset) getPipelineIDs(info beat.Info) ([]string, error) {
for _, ingestPipeline := range fs.manifest.IngestPipeline {
path, err := ApplyTemplate(fs.vars, ingestPipeline, false)
if err != nil {
return nil, fmt.Errorf("Error expanding vars on the ingest pipeline path: %v", err)
return nil, fmt.Errorf("Error expanding vars on the ingest pipeline path: %w", err)
}

pipelineIDs = append(pipelineIDs, FormatPipelineID(info.IndexPrefix, fs.mname, fs.name, path, info.Version))
Expand All @@ -432,32 +431,32 @@ func (fs *Fileset) GetPipelines(esVersion version.V) (pipelines []pipeline, err
for idx, ingestPipeline := range fs.manifest.IngestPipeline {
path, err := ApplyTemplate(fs.vars, ingestPipeline, false)
if err != nil {
return nil, fmt.Errorf("Error expanding vars on the ingest pipeline path: %v", err)
return nil, fmt.Errorf("Error expanding vars on the ingest pipeline path: %w", err)
}

strContents, err := ioutil.ReadFile(filepath.Join(fs.modulePath, fs.name, path))
if err != nil {
return nil, fmt.Errorf("Error reading pipeline file %s: %v", path, err)
return nil, fmt.Errorf("Error reading pipeline file %s: %w", path, err)
}

encodedString, err := ApplyTemplate(vars, string(strContents), true)
if err != nil {
return nil, fmt.Errorf("Error interpreting the template of the ingest pipeline: %v", err)
return nil, fmt.Errorf("Error interpreting the template of the ingest pipeline: %w", err)
}

var content map[string]interface{}
switch extension := strings.ToLower(filepath.Ext(path)); extension {
case ".json":
if err = json.Unmarshal([]byte(encodedString), &content); err != nil {
return nil, fmt.Errorf("Error JSON decoding the pipeline file: %s: %v", path, err)
return nil, fmt.Errorf("Error JSON decoding the pipeline file: %s: %w", path, err)
}
case ".yaml", ".yml":
if err = yaml.Unmarshal([]byte(encodedString), &content); err != nil {
return nil, fmt.Errorf("Error YAML decoding the pipeline file: %s: %v", path, err)
return nil, fmt.Errorf("Error YAML decoding the pipeline file: %s: %w", path, err)
}
newContent, err := FixYAMLMaps(content)
if err != nil {
return nil, fmt.Errorf("Failed to sanitize the YAML pipeline file: %s: %v", path, err)
return nil, fmt.Errorf("Failed to sanitize the YAML pipeline file: %s: %w", path, err)
}
content = newContent.(map[string]interface{})
default:
Expand Down
8 changes: 4 additions & 4 deletions filebeat/input/container/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
package container

import (
"fmt"

"github.com/elastic/beats/v7/filebeat/channel"
"github.com/elastic/beats/v7/filebeat/input"
"github.com/elastic/beats/v7/filebeat/input/log"
conf "github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/mapstr"

"github.com/pkg/errors"
)

func init() {
Expand All @@ -43,7 +43,7 @@ func NewInput(
// Wrap log input with custom docker settings
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return nil, errors.Wrap(err, "reading container input config")
return nil, fmt.Errorf("reading container input config: %w", err)
}

err := cfg.Merge(mapstr.M{
Expand All @@ -60,7 +60,7 @@ func NewInput(
"symlinks": true,
})
if err != nil {
return nil, errors.Wrap(err, "update input config")
return nil, fmt.Errorf("update input config: %w", err)
}

// Add stream to meta to ensure different state per stream
Expand Down
4 changes: 2 additions & 2 deletions filebeat/input/mqtt/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
package mqtt

import (
"fmt"
"strings"
"sync"
"time"

libmqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/pkg/errors"

"github.com/elastic/beats/v7/filebeat/channel"
"github.com/elastic/beats/v7/filebeat/input"
Expand Down Expand Up @@ -77,7 +77,7 @@ func newInput(
) (input.Input, error) {
config := defaultConfig()
if err := cfg.Unpack(&config); err != nil {
return nil, errors.Wrap(err, "reading mqtt input config")
return nil, fmt.Errorf("reading mqtt input config: %w", err)
}

out, err := connector.Connect(cfg)
Expand Down
5 changes: 2 additions & 3 deletions filebeat/input/syslog/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
package syslog

import (
"fmt"
"strings"
"sync"
"time"

"github.com/pkg/errors"

"github.com/elastic/beats/v7/filebeat/channel"
"github.com/elastic/beats/v7/filebeat/harvester"
"github.com/elastic/beats/v7/filebeat/input"
Expand Down Expand Up @@ -319,7 +318,7 @@ func newBeatEvent(timestamp time.Time, metadata inputsource.NetworkMetadata, fie

func mapValueToName(v int, m mapper) (string, error) {
if v < 0 || v >= len(m) {
return "", errors.Errorf("value out of bound: %d", v)
return "", fmt.Errorf("value out of bound: %d", v)
}
return m[v], nil
}
3 changes: 1 addition & 2 deletions filebeat/inputsource/common/streaming/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
package streaming

import (
"errors"
"io"
"net"
"time"

"github.com/pkg/errors"
)

// ErrMaxReadBuffer returns when too many bytes was read on the io.Reader
Expand Down
5 changes: 2 additions & 3 deletions filebeat/inputsource/common/streaming/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ package streaming
import (
"bufio"
"context"
"fmt"
"net"

"github.com/pkg/errors"

"github.com/elastic/beats/v7/filebeat/inputsource"
"github.com/elastic/elastic-agent-libs/logp"
)
Expand Down Expand Up @@ -76,7 +75,7 @@ func SplitHandlerFactory(family inputsource.Family, logger *logp.Logger, metadat
if IsMaxReadBufferErr(err) {
log.Errorw("split_client error", "error", err)
}
return errors.Wrap(err, string(family)+" split_client error")
return fmt.Errorf(string(family)+" split_client error: %w", err)
}
r.Reset()
callback(scanner.Bytes(), metadata)
Expand Down
3 changes: 1 addition & 2 deletions filebeat/inputsource/common/streaming/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"net"
"strings"
"sync"

"github.com/pkg/errors"

"github.com/elastic/beats/v7/filebeat/inputsource"
"github.com/elastic/beats/v7/libbeat/common/atomic"
"github.com/elastic/elastic-agent-libs/logp"
Expand Down
7 changes: 3 additions & 4 deletions filebeat/inputsource/unix/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
package unix

import (
"errors"
"fmt"
"os"
"os/user"
"runtime"
"strconv"

"github.com/pkg/errors"

"github.com/elastic/elastic-agent-libs/logp"
)

Expand All @@ -36,7 +35,7 @@ func cleanupStaleSocket(path string) error {
if os.IsNotExist(err) {
return nil
}
return errors.Wrapf(err, "cannot lstat unix socket file at location %s", path)
return fmt.Errorf("cannot lstat unix socket file at location %s: %w", path, err)
}

if runtime.GOOS != "windows" {
Expand All @@ -47,7 +46,7 @@ func cleanupStaleSocket(path string) error {
}

if err := os.Remove(path); err != nil {
return errors.Wrapf(err, "cannot remove existing unix socket file at location %s", path)
return fmt.Errorf("cannot remove existing unix socket file at location %s: %w", path, err)
}

return nil
Expand Down
Loading

0 comments on commit 3325ba1

Please sign in to comment.