Skip to content

Commit

Permalink
*: fix errcheck warnings
Browse files Browse the repository at this point in the history
Fixes part of coreos#1121
  • Loading branch information
sohankunkerkar committed Dec 10, 2020
1 parent 1c3dada commit 661bf94
Show file tree
Hide file tree
Showing 35 changed files with 198 additions and 188 deletions.
44 changes: 22 additions & 22 deletions internal/exec/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (e Engine) Run(stageName string) error {
systemBaseConfig, r, err := system.FetchBaseConfig(e.Logger, e.PlatformConfig.Name())
e.logReport(r)
if err != nil && err != providers.ErrNoProvider {
e.Logger.Crit("failed to acquire system base config: %v", err)
_ = e.Logger.Crit("failed to acquire system base config: %v", err)
return err
} else if err == nil {
e.fetchedConfigs = append(e.fetchedConfigs, fetchedConfig{
Expand All @@ -111,13 +111,13 @@ func (e Engine) Run(stageName string) error {
if err == resource.ErrNeedNet && stageName == "fetch-offline" {
err = SignalNeedNet()
if err != nil {
e.Logger.Crit("failed to signal neednet: %v", err)
_ = e.Logger.Crit("failed to signal neednet: %v", err)
}
return err
} else if err == errors.ErrEmpty {
e.Logger.Info("%v: ignoring user-provided config", err)
_ = e.Logger.Info("%v: ignoring user-provided config", err)
} else if err != nil {
e.Logger.Crit("failed to acquire config: %v", err)
_ = e.Logger.Crit("failed to acquire config: %v", err)
return err
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func (e Engine) Run(stageName string) error {
}
return err
}
e.Logger.Info("%s passed", stageName)
_ = e.Logger.Info("%s passed", stageName)
return nil
}

Expand Down Expand Up @@ -182,7 +182,7 @@ func (e *Engine) acquireConfig(stageName string) (cfg types.Config, err error) {
if err == nil {
for _, cfgInfo := range e.fetchedConfigs {
if logerr := logStructuredJournalEntry(cfgInfo); logerr != nil {
e.Logger.Info("failed to log systemd journal entry: %v", logerr)
_ = e.Logger.Info("failed to log systemd journal entry: %v", logerr)
}
}
}
Expand All @@ -201,14 +201,14 @@ func (e *Engine) acquireCachedConfig() (cfg types.Config, err error) {
return
}
if err = json.Unmarshal(b, &cfg); err != nil {
e.Logger.Crit("failed to parse cached config: %v", err)
_ = e.Logger.Crit("failed to parse cached config: %v", err)
return
}
// Create an http client and fetcher with the timeouts from the cached
// config
err = e.Fetcher.UpdateHttpTimeoutsAndCAs(cfg.Ignition.Timeouts, cfg.Ignition.Security.TLS.CertificateAuthorities, cfg.Ignition.Proxy)
if err != nil {
e.Logger.Crit("failed to update timeouts and CAs for fetcher: %v", err)
_ = e.Logger.Crit("failed to update timeouts and CAs for fetcher: %v", err)
return
}
return
Expand All @@ -223,7 +223,7 @@ func (e *Engine) acquireProviderConfig() (cfg types.Config, err error) {
emptyProxy := types.Proxy{}
err = e.Fetcher.UpdateHttpTimeoutsAndCAs(types.Timeouts{HTTPTotal: &timeout}, nil, emptyProxy)
if err != nil {
e.Logger.Crit("failed to update timeouts and CAs for fetcher: %v", err)
_ = e.Logger.Crit("failed to update timeouts and CAs for fetcher: %v", err)
return
}

Expand All @@ -233,42 +233,42 @@ func (e *Engine) acquireProviderConfig() (cfg types.Config, err error) {
// Continue if the provider config was empty as we want to write an empty
// cache config for use by other stages.
cfg = emptyConfig
e.Logger.Info("%v: provider config was empty, continuing with empty cache config", err)
_ = e.Logger.Info("%v: provider config was empty, continuing with empty cache config", err)
} else if err != nil {
e.Logger.Warning("failed to fetch config: %s", err)
_ = e.Logger.Warning("failed to fetch config: %s", err)
return
}

// Update the http client to use the timeouts and CAs from the newly fetched
// config
err = e.Fetcher.UpdateHttpTimeoutsAndCAs(cfg.Ignition.Timeouts, cfg.Ignition.Security.TLS.CertificateAuthorities, cfg.Ignition.Proxy)
if err != nil {
e.Logger.Crit("failed to update timeouts and CAs for fetcher: %v", err)
_ = e.Logger.Crit("failed to update timeouts and CAs for fetcher: %v", err)
return
}

err = e.Fetcher.RewriteCAsWithDataUrls(cfg.Ignition.Security.TLS.CertificateAuthorities)
if err != nil {
e.Logger.Crit("error handling CAs: %v", err)
_ = e.Logger.Crit("error handling CAs: %v", err)
return
}

rpt := validate.Validate(cfg, "json")
e.logReport(rpt)
if rpt.IsFatal() {
err = errors.ErrInvalid
e.Logger.Crit("merging configs resulted in an invalid config")
_ = e.Logger.Crit("merging configs resulted in an invalid config")
return
}

// Populate the config cache.
b, err := json.Marshal(cfg)
if err != nil {
e.Logger.Crit("failed to marshal cached config: %v", err)
_ = e.Logger.Crit("failed to marshal cached config: %v", err)
return
}
if err = renameio.WriteFile(e.ConfigCache, b, 0640); err != nil {
e.Logger.Crit("failed to write cached config: %v", err)
_ = e.Logger.Crit("failed to write cached config: %v", err)
return
}

Expand Down Expand Up @@ -382,7 +382,7 @@ func (e *Engine) renderConfig(cfg types.Config) (types.Config, error) {
func (e *Engine) fetchReferencedConfig(cfgRef types.Resource) (types.Config, error) {
// this is also already checked at validation time
if cfgRef.Source == nil {
e.Logger.Crit("invalid referenced config: %v", errors.ErrSourceRequired)
_ = e.Logger.Crit("invalid referenced config: %v", errors.ErrSourceRequired)
return types.Config{}, errors.ErrSourceRequired
}
u, err := url.Parse(*cfgRef.Source)
Expand Down Expand Up @@ -410,10 +410,10 @@ func (e *Engine) fetchReferencedConfig(cfgRef types.Resource) (types.Config, err

hash := sha512.Sum512(rawCfg)
if u.Scheme != "data" {
e.Logger.Debug("fetched referenced config at %s with SHA512: %s", *cfgRef.Source, hex.EncodeToString(hash[:]))
_ = e.Logger.Debug("fetched referenced config at %s with SHA512: %s", *cfgRef.Source, hex.EncodeToString(hash[:]))
} else {
// data url's might contain secrets
e.Logger.Debug("fetched referenced config from data url with SHA512: %s", hex.EncodeToString(hash[:]))
_ = e.Logger.Debug("fetched referenced config from data url with SHA512: %s", hex.EncodeToString(hash[:]))
}

e.fetchedConfigs = append(e.fetchedConfigs, fetchedConfig{
Expand Down Expand Up @@ -451,11 +451,11 @@ func (e Engine) logReport(r report.Report) {
for _, entry := range r.Entries {
switch entry.Kind {
case report.Error:
e.Logger.Crit("%v", entry)
_ = e.Logger.Crit("%v", entry)
case report.Warn:
e.Logger.Warning("%v", entry)
_ = e.Logger.Warning("%v", entry)
case report.Info:
e.Logger.Info("%v", entry)
_ = e.Logger.Info("%v", entry)
}
}
}
2 changes: 1 addition & 1 deletion internal/exec/stages/disks/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s stage) createDeviceAliases(devs []string) error {
if err != nil {
return fmt.Errorf("failed to create device alias for %q: %v", dev, err)
}
s.Logger.Info("created device alias for %q: %q -> %q", dev, util.DeviceAlias(dev), target)
_ = s.Logger.Info("created device alias for %q: %q -> %q", dev, util.DeviceAlias(dev), target)
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions internal/exec/stages/disks/filesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s stage) createFilesystem(fs types.Filesystem) error {
var err2 error
info, err2 = util.GetFilesystemInfo(devAlias, true)
if err2 == nil {
s.Logger.Warning("%v", err)
_ = s.Logger.Warning("%v", err)
}
err = err2
}
Expand All @@ -116,18 +116,18 @@ func (s stage) createFilesystem(fs types.Filesystem) error {
if err != nil {
return err
}
s.Logger.Info("found %s filesystem at %q with uuid %q and label %q", info.Type, fs.Device, info.UUID, info.Label)
_ = s.Logger.Info("found %s filesystem at %q with uuid %q and label %q", info.Type, fs.Device, info.UUID, info.Label)

if fs.WipeFilesystem == nil || !*fs.WipeFilesystem {
// If the filesystem isn't forcefully being created, then we need
// to check if it is of the correct type or that no filesystem exists.
if info.Type == *fs.Format &&
(fs.Label == nil || info.Label == *fs.Label) &&
(fs.UUID == nil || canonicalizeFilesystemUUID(info.Type, info.UUID) == canonicalizeFilesystemUUID(*fs.Format, *fs.UUID)) {
s.Logger.Info("filesystem at %q is already correctly formatted. Skipping mkfs...", fs.Device)
_ = s.Logger.Info("filesystem at %q is already correctly formatted. Skipping mkfs...", fs.Device)
return nil
} else if info.Type != "" {
s.Logger.Err("filesystem at %q is not of the correct type, label, or UUID (found %s, %q, %s) and a filesystem wipe was not requested", fs.Device, info.Type, info.Label, info.UUID)
_ = s.Logger.Err("filesystem at %q is not of the correct type, label, or UUID (found %s, %q, %s) and a filesystem wipe was not requested", fs.Device, info.Type, info.Label, info.UUID)
return ErrBadFilesystem
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/exec/stages/disks/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (s *stage) createLuks(config types.Config) error {
var err2 error
info, err2 = execUtil.GetFilesystemInfo(devAlias, true)
if err2 == nil {
s.Logger.Warning("%v", err)
_ = s.Logger.Warning("%v", err)
}
err = err2
}
Expand All @@ -187,15 +187,15 @@ func (s *stage) createLuks(config types.Config) error {
if err != nil {
return err
}
s.Logger.Info("found %s at %q with uuid %q and label %q", info.Type, *luks.Device, info.UUID, info.Label)
_ = s.Logger.Info("found %s at %q with uuid %q and label %q", info.Type, *luks.Device, info.UUID, info.Label)

if exists {
// Re-used devices cannot have Ignition generated key-files or be clevis devices so we cannot
// leak any key files when exiting the loop early
s.Logger.Info("volume at %q is already correctly formatted. Skipping...", *luks.Device)
_ = s.Logger.Info("volume at %q is already correctly formatted. Skipping...", *luks.Device)
continue
} else if info.Type != "" {
s.Logger.Err("volume at %q is not of the correct type, label, or UUID (found %s, %q, %s) and a volume wipe was not requested", *luks.Device, info.Type, info.Label, info.UUID)
_ = s.Logger.Err("volume at %q is not of the correct type, label, or UUID (found %s, %q, %s) and a volume wipe was not requested", *luks.Device, info.Type, info.Label, info.UUID)
return ErrBadVolume
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions internal/exec/stages/disks/partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (p PartitionList) Swap(i, j int) {
func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
if dev.WipeTable != nil && *dev.WipeTable {
op := sgdisk.Begin(s.Logger, devAlias)
s.Logger.Info("wiping partition table requested on %q", devAlias)
_ = s.Logger.Info("wiping partition table requested on %q", devAlias)
op.WipeTable(true)
op.Commit()
}
Expand Down Expand Up @@ -356,18 +356,18 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
// This is a translation of the matrix in the operator notes.
switch {
case !exists && !shouldExist:
s.Logger.Info("partition %d specified as nonexistant and no partition was found. Success.", part.Number)
_ = s.Logger.Info("partition %d specified as nonexistant and no partition was found. Success.", part.Number)
case !exists && shouldExist:
op.CreatePartition(part)
case exists && !shouldExist && !wipeEntry:
return fmt.Errorf("partition %d exists but is specified as nonexistant and wipePartitionEntry is false", part.Number)
case exists && !shouldExist && wipeEntry:
op.DeletePartition(part.Number)
case exists && shouldExist && matches:
s.Logger.Info("partition %d found with correct specifications", part.Number)
_ = s.Logger.Info("partition %d found with correct specifications", part.Number)
case exists && shouldExist && !wipeEntry && !matches:
if partitionMatchesResize(info, part) {
s.Logger.Info("resizing partition %d", part.Number)
_ = s.Logger.Info("resizing partition %d", part.Number)
op.DeletePartition(part.Number)
part.Number = info.Number
part.GUID = &info.GUID
Expand All @@ -379,7 +379,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
return fmt.Errorf("Partition %d didn't match: %v", part.Number, matchErr)
}
case exists && shouldExist && wipeEntry && !matches:
s.Logger.Info("partition %d did not meet specifications, wiping partition entry and recreating", part.Number)
_ = s.Logger.Info("partition %d did not meet specifications, wiping partition entry and recreating", part.Number)
op.DeletePartition(part.Number)
op.CreatePartition(part)
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/stages/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ func (stage) Name() string {

func (s stage) Run(_ types.Config) error {
// Nothing - all we do is fetch and allow anything else in the initramfs to run
s.Logger.Info("fetch complete")
_ = s.Logger.Info("fetch complete")
return nil
}
2 changes: 1 addition & 1 deletion internal/exec/stages/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s stage) Run(config types.Config) error {
// we only collect filenames if we need to.
func (s *stage) checkRelabeling() error {
if !distro.SelinuxRelabel() {
s.Logger.Debug("compiled without relabeling support, skipping")
_ = s.Logger.Debug("compiled without relabeling support, skipping")
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/exec/stages/files/filesystemEntries.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (tmp linkEntry) create(l *log.Logger, u util.Util) error {
if !os.SameFile(st, targetst) {
return fmt.Errorf("error creating hard link %s: a file already exists at that path but is not the target and overwrite is false", s.Path)
}
l.Info("Hardlink %s to %s already exists, doing nothing", s.Path, s.Target)
_ = l.Info("Hardlink %s to %s already exists, doing nothing", s.Path, s.Target)
return nil
case !hard:
// if the existing file is a symlink, check that its target is correct
Expand All @@ -280,7 +280,7 @@ func (tmp linkEntry) create(l *log.Logger, u util.Util) error {
} else if filepath.Clean(target) != filepath.Clean(s.Target) {
return fmt.Errorf("error creating symlink %s: a symlink exists at that path but points to %s, not %s and overwrite is false", s.Path, target, s.Target)
} else {
l.Info("Symlink %s to %s already exists, doing nothing", s.Path, s.Target)
_ = l.Info("Symlink %s to %s already exists, doing nothing", s.Path, s.Target)
return nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/exec/stages/files/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {
}
f, err := u.FileFromSystemdUnitDropin(unit, dropin, runtime)
if err != nil {
s.Logger.Crit("error converting systemd dropin: %v", err)
_ = s.Logger.Crit("error converting systemd dropin: %v", err)
return err
}
relabelPath := f.Node.Path
Expand Down Expand Up @@ -237,7 +237,7 @@ func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {

f, err := u.FileFromSystemdUnit(unit, runtime)
if err != nil {
s.Logger.Crit("error converting unit: %v", err)
_ = s.Logger.Crit("error converting unit: %v", err)
return err
}
relabelPath := f.Node.Path
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newFetchOp(l *log.Logger, node types.Node, contents types.Resource) (FetchO

hasher, err := util.GetHasher(contents.Verification)
if err != nil {
l.Crit("Error verifying file %q: %v", node.Path, err)
_ = l.Crit("Error verifying file %q: %v", node.Path, err)
return FetchOp{}, err
}

Expand All @@ -67,7 +67,7 @@ func newFetchOp(l *log.Logger, node types.Node, contents types.Resource) (FetchO
_, expectedSumString, _ := util.HashParts(contents.Verification)
expectedSum, err = hex.DecodeString(expectedSumString)
if err != nil {
l.Crit("Error parsing verification string %q: %v", expectedSumString, err)
_ = l.Crit("Error parsing verification string %q: %v", expectedSumString, err)
return FetchOp{}, err
}
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func (u Util) PerformFetch(f FetchOp) error {

err = u.Fetcher.Fetch(f.Url, tmp, f.FetchOptions)
if err != nil {
u.Crit("Error fetching file %q: %v", path, err)
_ = u.Crit("Error fetching file %q: %v", path, err)
return err
}

Expand Down
12 changes: 6 additions & 6 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func New(logToStdout bool) Logger {
logger.ops, err = syslog.New(syslog.LOG_DEBUG, "ignition")
if err != nil {
logger.ops = Stdout{}
logger.Err("unable to open syslog: %v", err)
_ = logger.Err("unable to open syslog: %v", err)
}
return logger
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (l *Logger) PushPrefix(format string, a ...interface{}) {
// The prefix stack is concatenated in FIFO order and prefixed to the start of every message logged via Logger.
func (l *Logger) PopPrefix() {
if len(l.prefixStack) == 0 {
l.Debug("popped from empty stack")
_ = l.Debug("popped from empty stack")
return
}
l.prefixStack = l.prefixStack[:len(l.prefixStack)-1]
Expand All @@ -140,7 +140,7 @@ func (l *Logger) LogCmd(cmd *exec.Cmd, format string, a ...interface{}) (int, er
code := -1
f := func() error {
cmdLine := QuotedCmd(cmd)
l.Debug("executing: %s", cmdLine)
_ = l.Debug("executing: %s", cmdLine)

stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
Expand Down Expand Up @@ -175,17 +175,17 @@ func (l *Logger) LogOp(op func() error, format string, a ...interface{}) error {

// logStart logs the start of a multi-step/substantial/time-consuming operation.
func (l Logger) logStart(format string, a ...interface{}) {
l.Info(fmt.Sprintf("[started] %s", format), a...)
_ = l.Info(fmt.Sprintf("[started] %s", format), a...)
}

// logFail logs the failure of a multi-step/substantial/time-consuming operation.
func (l Logger) logFail(format string, a ...interface{}) {
l.Crit(fmt.Sprintf("[failed] %s", format), a...)
_ = l.Crit(fmt.Sprintf("[failed] %s", format), a...)
}

// logFinish logs the completion of a multi-step/substantial/time-consuming operation.
func (l Logger) logFinish(format string, a ...interface{}) {
l.Info(fmt.Sprintf("[finished] %s", format), a...)
_ = l.Info(fmt.Sprintf("[finished] %s", format), a...)
}

// log logs a formatted message using the supplied logFunc.
Expand Down
Loading

0 comments on commit 661bf94

Please sign in to comment.