chore: Fix linter findings for errorlint (part1) (#12701)
Co-authored-by: Pawel Zak <Pawel Zak>
This commit is contained in:
parent
6e72fee7b1
commit
f7949ca68a
|
|
@ -196,36 +196,31 @@ func (a *Agent) initPlugins() error {
|
||||||
}
|
}
|
||||||
err := input.Init()
|
err := input.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not initialize input %s: %v",
|
return fmt.Errorf("could not initialize input %s: %w", input.LogName(), err)
|
||||||
input.LogName(), err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, processor := range a.Config.Processors {
|
for _, processor := range a.Config.Processors {
|
||||||
err := processor.Init()
|
err := processor.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not initialize processor %s: %v",
|
return fmt.Errorf("could not initialize processor %s: %w", processor.LogName(), err)
|
||||||
processor.LogName(), err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, aggregator := range a.Config.Aggregators {
|
for _, aggregator := range a.Config.Aggregators {
|
||||||
err := aggregator.Init()
|
err := aggregator.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not initialize aggregator %s: %v",
|
return fmt.Errorf("could not initialize aggregator %s: %w", aggregator.LogName(), err)
|
||||||
aggregator.LogName(), err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, processor := range a.Config.AggProcessors {
|
for _, processor := range a.Config.AggProcessors {
|
||||||
err := processor.Init()
|
err := processor.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not initialize processor %s: %v",
|
return fmt.Errorf("could not initialize processor %s: %w", processor.LogName(), err)
|
||||||
processor.LogName(), err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, output := range a.Config.Outputs {
|
for _, output := range a.Config.Outputs {
|
||||||
err := output.Init()
|
err := output.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not initialize output %s: %v",
|
return fmt.Errorf("could not initialize output %s: %w", output.LogName(), err)
|
||||||
output.LogName(), err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ func runApp(args []string, outputBuffer io.Writer, pprof Server, c TelegrafConfi
|
||||||
err := PrintInputConfig(cCtx.String("usage"), outputBuffer)
|
err := PrintInputConfig(cCtx.String("usage"), outputBuffer)
|
||||||
err2 := PrintOutputConfig(cCtx.String("usage"), outputBuffer)
|
err2 := PrintOutputConfig(cCtx.String("usage"), outputBuffer)
|
||||||
if err != nil && err2 != nil {
|
if err != nil && err2 != nil {
|
||||||
return fmt.Errorf("%s and %s", err, err2)
|
return fmt.Errorf("%w and %w", err, err2)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
|
|
|
||||||
|
|
@ -151,9 +151,9 @@ func (t *Telegraf) reloadLoop() error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := t.runAgent(ctx, cfg)
|
err = t.runAgent(ctx, cfg)
|
||||||
if err != nil && err != context.Canceled {
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
return fmt.Errorf("[telegraf] Error running agent: %v", err)
|
return fmt.Errorf("[telegraf] Error running agent: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -473,7 +473,7 @@ func (c *Config) LoadAll(configFiles ...string) error {
|
||||||
func (c *Config) LoadConfigData(data []byte) error {
|
func (c *Config) LoadConfigData(data []byte) error {
|
||||||
tbl, err := parseConfig(data)
|
tbl, err := parseConfig(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing data: %s", err)
|
return fmt.Errorf("error parsing data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse tags tables first:
|
// Parse tags tables first:
|
||||||
|
|
@ -484,7 +484,7 @@ func (c *Config) LoadConfigData(data []byte) error {
|
||||||
return fmt.Errorf("invalid configuration, bad table name %q", tableName)
|
return fmt.Errorf("invalid configuration, bad table name %q", tableName)
|
||||||
}
|
}
|
||||||
if err = c.toml.UnmarshalTable(subTable, c.Tags); err != nil {
|
if err = c.toml.UnmarshalTable(subTable, c.Tags); err != nil {
|
||||||
return fmt.Errorf("error parsing table name %q: %s", tableName, err)
|
return fmt.Errorf("error parsing table name %q: %w", tableName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -614,7 +614,7 @@ func (c *Config) LoadConfigData(data []byte) error {
|
||||||
case []*ast.Table:
|
case []*ast.Table:
|
||||||
for _, t := range pluginSubTable {
|
for _, t := range pluginSubTable {
|
||||||
if err = c.addAggregator(pluginName, t); err != nil {
|
if err = c.addAggregator(pluginName, t); err != nil {
|
||||||
return fmt.Errorf("error parsing %s, %s", pluginName, err)
|
return fmt.Errorf("error parsing %s, %w", pluginName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -632,7 +632,7 @@ func (c *Config) LoadConfigData(data []byte) error {
|
||||||
case []*ast.Table:
|
case []*ast.Table:
|
||||||
for _, t := range pluginSubTable {
|
for _, t := range pluginSubTable {
|
||||||
if err = c.addSecretStore(pluginName, t); err != nil {
|
if err = c.addSecretStore(pluginName, t); err != nil {
|
||||||
return fmt.Errorf("error parsing %s, %s", pluginName, err)
|
return fmt.Errorf("error parsing %s, %w", pluginName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -648,7 +648,7 @@ func (c *Config) LoadConfigData(data []byte) error {
|
||||||
// identifiers are present
|
// identifiers are present
|
||||||
default:
|
default:
|
||||||
if err = c.addInput(name, subTable); err != nil {
|
if err = c.addInput(name, subTable); err != nil {
|
||||||
return fmt.Errorf("error parsing %s, %s", name, err)
|
return fmt.Errorf("error parsing %s, %w", name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -726,7 +726,7 @@ func fetchConfig(u *url.URL) ([]byte, error) {
|
||||||
body, err, retry := func() ([]byte, error, bool) {
|
body, err, retry := func() ([]byte, error, bool) {
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("retry %d of %d failed connecting to HTTP config server %s", i, retries, err), false
|
return nil, fmt.Errorf("retry %d of %d failed connecting to HTTP config server: %w", i, retries, err), false
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
|
@ -871,13 +871,13 @@ func (c *Config) LinkSecrets() error {
|
||||||
}
|
}
|
||||||
resolver, err := store.GetResolver(key)
|
resolver, err := store.GetResolver(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("retrieving resolver for %q failed: %v", ref, err)
|
return fmt.Errorf("retrieving resolver for %q failed: %w", ref, err)
|
||||||
}
|
}
|
||||||
resolvers[ref] = resolver
|
resolvers[ref] = resolver
|
||||||
}
|
}
|
||||||
// Inject the resolver list into the secret
|
// Inject the resolver list into the secret
|
||||||
if err := s.Link(resolvers); err != nil {
|
if err := s.Link(resolvers); err != nil {
|
||||||
return fmt.Errorf("retrieving resolver failed: %v", err)
|
return fmt.Errorf("retrieving resolver failed: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,14 @@ func (di *DeprecationInfo) determineEscalation(telegrafVersion *semver.Version)
|
||||||
|
|
||||||
since, err := semver.NewVersion(di.info.Since)
|
since, err := semver.NewVersion(di.info.Since)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since, err)
|
return fmt.Errorf("cannot parse 'since' version %q: %w", di.info.Since, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var removal *semver.Version
|
var removal *semver.Version
|
||||||
if di.info.RemovalIn != "" {
|
if di.info.RemovalIn != "" {
|
||||||
removal, err = semver.NewVersion(di.info.RemovalIn)
|
removal, err = semver.NewVersion(di.info.RemovalIn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn, err)
|
return fmt.Errorf("cannot parse 'removal' version %q: %w", di.info.RemovalIn, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
removal = &semver.Version{Major: since.Major}
|
removal = &semver.Version{Major: since.Major}
|
||||||
|
|
@ -116,7 +116,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := info.determineEscalation(c.version); err != nil {
|
if err := info.determineEscalation(c.version); err != nil {
|
||||||
panic(fmt.Errorf("plugin %q: %v", info.Name, err))
|
panic(fmt.Errorf("plugin %q: %w", info.Name, err))
|
||||||
}
|
}
|
||||||
if info.LogLevel != telegraf.None {
|
if info.LogLevel != telegraf.None {
|
||||||
c.incrementPluginDeprecations(category)
|
c.incrementPluginDeprecations(category)
|
||||||
|
|
@ -148,7 +148,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{
|
||||||
optionInfo.info.RemovalIn = tags[1]
|
optionInfo.info.RemovalIn = tags[1]
|
||||||
}
|
}
|
||||||
if err := optionInfo.determineEscalation(c.version); err != nil {
|
if err := optionInfo.determineEscalation(c.version); err != nil {
|
||||||
panic(fmt.Errorf("plugin %q option %q: %v", info.Name, field.Name, err))
|
panic(fmt.Errorf("plugin %q option %q: %w", info.Name, field.Name, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if optionInfo.LogLevel != telegraf.None {
|
if optionInfo.LogLevel != telegraf.None {
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ func (s *Secret) EqualTo(ref []byte) (bool, error) {
|
||||||
// Get a locked-buffer of the secret to perform the comparison
|
// Get a locked-buffer of the secret to perform the comparison
|
||||||
lockbuf, err := s.enclave.Open()
|
lockbuf, err := s.enclave.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("opening enclave failed: %v", err)
|
return false, fmt.Errorf("opening enclave failed: %w", err)
|
||||||
}
|
}
|
||||||
defer lockbuf.Destroy()
|
defer lockbuf.Destroy()
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ func (s *Secret) Get() ([]byte, error) {
|
||||||
// Decrypt the secret so we can return it
|
// Decrypt the secret so we can return it
|
||||||
lockbuf, err := s.enclave.Open()
|
lockbuf, err := s.enclave.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("opening enclave failed: %v", err)
|
return nil, fmt.Errorf("opening enclave failed: %w", err)
|
||||||
}
|
}
|
||||||
defer lockbuf.Destroy()
|
defer lockbuf.Destroy()
|
||||||
secret := lockbuf.Bytes()
|
secret := lockbuf.Bytes()
|
||||||
|
|
@ -179,7 +179,7 @@ func (s *Secret) Link(resolvers map[string]telegraf.ResolveFunc) error {
|
||||||
}
|
}
|
||||||
lockbuf, err := s.enclave.Open()
|
lockbuf, err := s.enclave.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("opening enclave failed: %v", err)
|
return fmt.Errorf("opening enclave failed: %w", err)
|
||||||
}
|
}
|
||||||
defer lockbuf.Destroy()
|
defer lockbuf.Destroy()
|
||||||
secret := lockbuf.Bytes()
|
secret := lockbuf.Bytes()
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ func (r *GzipReader) Read(b []byte) (int, error) {
|
||||||
|
|
||||||
// Since multistream is disabled, io.EOF indicates the end of the gzip
|
// Since multistream is disabled, io.EOF indicates the end of the gzip
|
||||||
// sequence. On the next read we must read the next gzip header.
|
// sequence. On the next read we must read the next gzip header.
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
r.endOfStream = true
|
r.endOfStream = true
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
@ -225,7 +225,7 @@ func (d *GzipDecoder) Decode(data []byte) ([]byte, error) {
|
||||||
d.buf.Reset()
|
d.buf.Reset()
|
||||||
|
|
||||||
_, err = d.buf.ReadFrom(d.reader)
|
_, err = d.buf.ReadFrom(d.reader)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && !errors.Is(err, io.EOF) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = d.reader.Close()
|
err = d.reader.Close()
|
||||||
|
|
@ -256,7 +256,7 @@ func (d *ZlibDecoder) Decode(data []byte) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_, err = io.Copy(d.buf, r)
|
_, err = io.Copy(d.buf, r)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && !errors.Is(err, io.EOF) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = r.Close()
|
err = r.Close()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -135,7 +136,8 @@ func OnClientError(client *http.Client, err error) {
|
||||||
// connection this ensures that next interval a new connection will be
|
// connection this ensures that next interval a new connection will be
|
||||||
// used and name lookup will be performed.
|
// used and name lookup will be performed.
|
||||||
// https://github.com/golang/go/issues/36026
|
// https://github.com/golang/go/issues/36026
|
||||||
if err, ok := err.(*url.Error); ok && err.Timeout() {
|
var urlErr *url.Error
|
||||||
|
if errors.As(err, &urlErr) && urlErr.Timeout() {
|
||||||
client.CloseIdleConnections()
|
client.CloseIdleConnections()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -184,8 +184,9 @@ func AlignTime(tm time.Time, interval time.Duration) time.Time {
|
||||||
// and returns the exit status and true
|
// and returns the exit status and true
|
||||||
// if error is not exit status, will return 0 and false
|
// if error is not exit status, will return 0 and false
|
||||||
func ExitStatus(err error) (int, bool) {
|
func ExitStatus(err error) (int, bool) {
|
||||||
if exiterr, ok := err.(*exec.ExitError); ok {
|
var exitErr *exec.ExitError
|
||||||
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
|
if errors.As(err, &exitErr) {
|
||||||
|
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
|
||||||
return status.ExitStatus(), true
|
return status.ExitStatus(), true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ func (p *Process) cmdStart() error {
|
||||||
p.Log.Infof("Starting process: %s %s", p.name, p.args)
|
p.Log.Infof("Starting process: %s %s", p.name, p.args)
|
||||||
|
|
||||||
if err := p.Cmd.Start(); err != nil {
|
if err := p.Cmd.Start(); err != nil {
|
||||||
return fmt.Errorf("error starting process: %s", err)
|
return fmt.Errorf("error starting process: %w", err)
|
||||||
}
|
}
|
||||||
atomic.StoreInt32(&p.pid, int32(p.Cmd.Process.Pid))
|
atomic.StoreInt32(&p.pid, int32(p.Cmd.Process.Pid))
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func walkPaths(paths []string, log telegraf.Logger) ([]string, error) {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return folders, fmt.Errorf("couldn't walk path %q: %v", mibPath, err)
|
return folders, fmt.Errorf("couldn't walk path %q: %w", mibPath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return folders, nil
|
return folders, nil
|
||||||
|
|
|
||||||
|
|
@ -54,41 +54,41 @@ func (f *Filter) Compile() error {
|
||||||
var err error
|
var err error
|
||||||
f.nameDropFilter, err = filter.Compile(f.NameDrop)
|
f.nameDropFilter, err = filter.Compile(f.NameDrop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling 'namedrop', %s", err)
|
return fmt.Errorf("error compiling 'namedrop', %w", err)
|
||||||
}
|
}
|
||||||
f.namePassFilter, err = filter.Compile(f.NamePass)
|
f.namePassFilter, err = filter.Compile(f.NamePass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling 'namepass', %s", err)
|
return fmt.Errorf("error compiling 'namepass', %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.fieldDropFilter, err = filter.Compile(f.FieldDrop)
|
f.fieldDropFilter, err = filter.Compile(f.FieldDrop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling 'fielddrop', %s", err)
|
return fmt.Errorf("error compiling 'fielddrop', %w", err)
|
||||||
}
|
}
|
||||||
f.fieldPassFilter, err = filter.Compile(f.FieldPass)
|
f.fieldPassFilter, err = filter.Compile(f.FieldPass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling 'fieldpass', %s", err)
|
return fmt.Errorf("error compiling 'fieldpass', %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.tagExcludeFilter, err = filter.Compile(f.TagExclude)
|
f.tagExcludeFilter, err = filter.Compile(f.TagExclude)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling 'tagexclude', %s", err)
|
return fmt.Errorf("error compiling 'tagexclude', %w", err)
|
||||||
}
|
}
|
||||||
f.tagIncludeFilter, err = filter.Compile(f.TagInclude)
|
f.tagIncludeFilter, err = filter.Compile(f.TagInclude)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling 'taginclude', %s", err)
|
return fmt.Errorf("error compiling 'taginclude', %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range f.TagDropFilters {
|
for i := range f.TagDropFilters {
|
||||||
f.TagDropFilters[i].filter, err = filter.Compile(f.TagDropFilters[i].Values)
|
f.TagDropFilters[i].filter, err = filter.Compile(f.TagDropFilters[i].Values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling 'tagdrop', %s", err)
|
return fmt.Errorf("error compiling 'tagdrop', %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range f.TagPassFilters {
|
for i := range f.TagPassFilters {
|
||||||
f.TagPassFilters[i].filter, err = filter.Compile(f.TagPassFilters[i].Values)
|
f.TagPassFilters[i].filter, err = filter.Compile(f.TagPassFilters[i].Values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling 'tagpass', %s", err)
|
return fmt.Errorf("error compiling 'tagpass', %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func (c *Container) Start() error {
|
||||||
|
|
||||||
container, err := testcontainers.GenericContainer(c.ctx, req)
|
container, err := testcontainers.GenericContainer(c.ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("container failed to start: %s", err)
|
return fmt.Errorf("container failed to start: %w", err)
|
||||||
}
|
}
|
||||||
c.container = container
|
c.container = container
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ func (c *Container) Start() error {
|
||||||
c.container.FollowOutput(&c.Logs)
|
c.container.FollowOutput(&c.Logs)
|
||||||
err = c.container.StartLogProducer(c.ctx)
|
err = c.container.StartLogProducer(c.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("log producer failed: %s", err)
|
return fmt.Errorf("log producer failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Address = "localhost"
|
c.Address = "localhost"
|
||||||
|
|
@ -81,7 +81,7 @@ func (c *Container) Start() error {
|
||||||
err = c.LookupMappedPorts()
|
err = c.LookupMappedPorts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Terminate()
|
c.Terminate()
|
||||||
return fmt.Errorf("port lookup failed: %s", err)
|
return fmt.Errorf("port lookup failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -110,7 +110,7 @@ func (c *Container) LookupMappedPorts() error {
|
||||||
|
|
||||||
p, err := c.container.MappedPort(c.ctx, nat.Port(port))
|
p, err := c.container.MappedPort(c.ctx, nat.Port(port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to find '%s' - %s", port, err)
|
return fmt.Errorf("failed to find %q: %w", port, err)
|
||||||
}
|
}
|
||||||
fmt.Printf("mapped container port '%s' to host port '%s'\n", port, p.Port())
|
fmt.Printf("mapped container port '%s' to host port '%s'\n", port, p.Port())
|
||||||
c.Ports[port] = p.Port()
|
c.Ports[port] = p.Port()
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ func ParseMetricsFrom(lines []string, header string, parser LineParser) ([]teleg
|
||||||
|
|
||||||
m, err := parser.ParseLine(content)
|
m, err := parser.ParseLine(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to parse metric in %q failed: %v", content, err)
|
return nil, fmt.Errorf("unable to parse metric in %q failed: %w", content, err)
|
||||||
}
|
}
|
||||||
metrics = append(metrics, m)
|
metrics = append(metrics, m)
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +104,7 @@ func ParseMetricsFromFile(filename string, parser telegraf.Parser) ([]telegraf.M
|
||||||
|
|
||||||
nonutc, err := parser.Parse(line)
|
nonutc, err := parser.Parse(line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to parse metric in %q failed: %v", line, err)
|
return nil, fmt.Errorf("unable to parse metric in %q failed: %w", line, err)
|
||||||
}
|
}
|
||||||
for _, m := range nonutc {
|
for _, m := range nonutc {
|
||||||
// The timezone needs to be UTC to match the timestamp test results
|
// The timezone needs to be UTC to match the timestamp test results
|
||||||
|
|
|
||||||
|
|
@ -95,11 +95,11 @@ func (s *selection) importFiles(configurations []string) error {
|
||||||
for _, cfg := range configurations {
|
for _, cfg := range configurations {
|
||||||
buf, err := config.LoadConfigFile(cfg)
|
buf, err := config.LoadConfigFile(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("reading %q failed: %v", cfg, err)
|
return fmt.Errorf("reading %q failed: %w", cfg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.extractPluginsFromConfig(buf); err != nil {
|
if err := s.extractPluginsFromConfig(buf); err != nil {
|
||||||
return fmt.Errorf("extracting plugins from %q failed: %v", cfg, err)
|
return fmt.Errorf("extracting plugins from %q failed: %w", cfg, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,12 @@ func (c *Container) Create(image string) error {
|
||||||
c.client = LXDClient{}
|
c.client = LXDClient{}
|
||||||
err := c.client.Connect()
|
err := c.client.Connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to connect to lxd: %v", err)
|
return fmt.Errorf("failed to connect to lxd: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.client.Create(c.Name, "images", image)
|
err = c.client.Create(c.Name, "images", image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create instance: %v", err)
|
return fmt.Errorf("failed to create instance: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// at this point the container is created, so on any error during setup
|
// at this point the container is created, so on any error during setup
|
||||||
|
|
@ -45,7 +45,7 @@ func (c *Container) Create(image string) error {
|
||||||
err = c.client.Start(c.Name)
|
err = c.client.Start(c.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Delete()
|
c.Delete()
|
||||||
return fmt.Errorf("failed to start instance: %v", err)
|
return fmt.Errorf("failed to start instance: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.detectPackageManager(); err != nil {
|
if err := c.detectPackageManager(); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func (c *LXDClient) Push(name string, src string, dst string) error {
|
||||||
fmt.Printf("cp %s %s%s\n", src, name, dst)
|
fmt.Printf("cp %s %s%s\n", src, name, dst)
|
||||||
f, err := os.Open(src)
|
f, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error reading %s: %v", src, err)
|
return fmt.Errorf("error reading %s: %w", src, err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,13 +78,13 @@ func extractIncludeBlock(txt []byte, includesEx *regexp.Regexp, root string) *in
|
||||||
func insertInclude(buf *bytes.Buffer, include string) error {
|
func insertInclude(buf *bytes.Buffer, include string) error {
|
||||||
file, err := os.Open(include)
|
file, err := os.Open(include)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("opening include %q failed: %v", include, err)
|
return fmt.Errorf("opening include %q failed: %w", include, err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// Write the include and make sure we get a newline
|
// Write the include and make sure we get a newline
|
||||||
if _, err := io.Copy(buf, file); err != nil {
|
if _, err := io.Copy(buf, file); err != nil {
|
||||||
return fmt.Errorf("inserting include %q failed: %v", include, err)
|
return fmt.Errorf("inserting include %q failed: %w", include, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -72,7 +73,7 @@ func findHashes(body io.Reader, version string) (map[string]string, error) {
|
||||||
//the end of the file, or the HTML was malformed
|
//the end of the file, or the HTML was malformed
|
||||||
if tokenType == html.ErrorToken {
|
if tokenType == html.ErrorToken {
|
||||||
err := htmlTokens.Err()
|
err := htmlTokens.Err()
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
//end of the file, break out of the loop
|
//end of the file, break out of the loop
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue