packer: address errcheck lint errors

In a couple places in the codebase we didn't check the errors from
functions we execute.

In some cases this is harmless (or at least ignorable), but others may
need to log what went wrong, so for all the reported occurrences we
either ignore explicitly or handle the error with a log.
protobuf-serialization
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 805015c360
commit e8d3a55b5f

@ -416,15 +416,15 @@ func copyOutput(r io.Reader, doneCh chan<- struct{}) {
wg.Add(3)
go func() {
defer wg.Done()
io.Copy(os.Stderr, stderrR)
_, _ = io.Copy(os.Stderr, stderrR)
}()
go func() {
defer wg.Done()
io.Copy(os.Stdout, stdoutR)
_, _ = io.Copy(os.Stdout, stdoutR)
}()
go func() {
defer wg.Done()
io.Copy(os.Stdout, defaultR)
_, _ = io.Copy(os.Stdout, defaultR)
}()
wg.Wait()

@ -869,7 +869,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
}
copyFrom, err = f.Open()
if err != nil {
multierror.Append(errs, fmt.Errorf("failed to open temp file: %w", err))
errs = multierror.Append(errs, fmt.Errorf("failed to open temp file: %w", err))
return nil, errs
}
break

@ -198,7 +198,7 @@ func (c *PluginClient) Kill() {
return
}
cmd.Process.Kill()
_ = cmd.Process.Kill()
// Wait for the client to finish logging so we have a complete log
<-c.doneLogging
@ -247,7 +247,7 @@ func (c *PluginClient) Start() (net.Addr, error) {
r := recover()
if err != nil || r != nil {
cmd.Process.Kill()
_ = cmd.Process.Kill()
}
if r != nil {
@ -264,7 +264,7 @@ func (c *PluginClient) Start() (net.Addr, error) {
defer stdout_w.Close()
// Wait for the command to end.
cmd.Wait()
_ = cmd.Wait()
// Log and make sure to flush the logs write away
log.Printf("%s: plugin process exited\n", cmd.Path)
@ -377,7 +377,7 @@ func (c *PluginClient) logStderr(r io.Reader) {
for {
line, err := bufR.ReadString('\n')
if line != "" {
c.config.Stderr.Write([]byte(line))
_, _ = c.config.Stderr.Write([]byte(line))
line = strings.TrimRightFunc(line, unicode.IsSpace)
@ -406,7 +406,10 @@ func (c *PluginClient) Client() (*packerrpc.Client, error) {
if tcpConn, ok := conn.(*net.TCPConn); ok {
// Make sure to set keep alive so that the connection doesn't die
tcpConn.SetKeepAlive(true)
err = tcpConn.SetKeepAlive(true)
if err != nil {
log.Printf("[ERROR] failed to set keepalive for TCP connection to plugin: %s. Some instability may occur.", err)
}
}
client, err := packerrpc.NewClient(conn)

@ -62,7 +62,7 @@ func (p *UiProgressBar) TrackProgress(src string, currentSize, totalSize int64,
newPb.Finish()
p.pbs--
if p.pbs <= 0 {
p.pool.Stop()
_ = p.pool.Stop()
p.pool = nil
}
return nil

@ -151,7 +151,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa
return nil, false, true, fmt.Errorf("unable to compute %s hash for %s", ct, art)
}
fr.Close()
fw.WriteString(fmt.Sprintf("%x\t%s\n", h.Sum(nil), filepath.Base(art)))
_, _ = fw.WriteString(fmt.Sprintf("%x\t%s\n", h.Sum(nil), filepath.Base(art)))
fw.Close()
h.Reset()
}

@ -371,7 +371,7 @@ func makePgzipWriter(output io.WriteCloser, compressionLevel int) (io.WriteClose
if err != nil {
return nil, ErrInvalidCompressionLevel
}
gzipWriter.SetConcurrency(500000, runtime.GOMAXPROCS(-1))
_ = gzipWriter.SetConcurrency(500000, runtime.GOMAXPROCS(-1))
return gzipWriter, nil
}

@ -203,7 +203,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packe
// Write our contents to it
writer := bufio.NewWriter(tf)
writer.WriteString(fmt.Sprintf("#!%s\n", p.config.InlineShebang))
_, _ = writer.WriteString(fmt.Sprintf("#!%s\n", p.config.InlineShebang))
for _, command := range p.config.Inline {
p.config.ctx.Data = generatedData
command, err := interpolate.Render(command, &p.config.ctx)

@ -165,7 +165,10 @@ var waitForRestart = func(ctx context.Context, p *Provisioner, comm packersdk.Co
if cmd.ExitStatus() == 0 {
// Cancel reboot we created to test if machine was already rebooting
cmd = &packersdk.RemoteCmd{Command: abortcommand}
cmd.RunWithUi(ctx, comm, ui)
err = cmd.RunWithUi(ctx, comm, ui)
if err != nil {
log.Printf("[ERROR] failed to run remote shutdown command: %s, build will likely hang.", err)
}
break
}
}
@ -249,7 +252,11 @@ var waitForCommunicator = func(ctx context.Context, p *Provisioner) error {
cmdModuleLoad.Stdout = &buf
cmdModuleLoad.Stdout = io.MultiWriter(cmdModuleLoad.Stdout, &buf2)
cmdModuleLoad.RunWithUi(ctx, p.comm, p.ui)
err := cmdModuleLoad.RunWithUi(ctx, p.comm, p.ui)
if err != nil {
log.Printf("[ERROR] failed to run restart command on guest: %s. Build may hang.", err)
}
stdoutToRead := buf2.String()
if !strings.Contains(stdoutToRead, "restarted.") {

Loading…
Cancel
Save