Skip to content

Commit

Permalink
log actual error when they exist during config reading process
Browse files Browse the repository at this point in the history
  • Loading branch information
olamilekan000 committed Jan 5, 2025
1 parent 1f32bf2 commit 72dc9ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions environment/vm/lima/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lima

import (
"context"
"encoding/json"
"fmt"
"path/filepath"
Expand All @@ -9,9 +10,13 @@ import (
const configFile = "/etc/colima/colima.json"

func (l limaVM) getConf() map[string]string {
log := l.Logger(context.Background())

obj := map[string]string{}
b, err := l.Read(configFile)
if err != nil {
log.Tracef("failed to read config file %w", err)

Check failure on line 18 in environment/vm/lima/config.go

View workflow job for this annotation

GitHub Actions / lint

printf: (*github.com/sirupsen/logrus.Entry).Tracef does not support error-wrapping directive %w (govet)

Check failure on line 18 in environment/vm/lima/config.go

View workflow job for this annotation

GitHub Actions / build-macos

(*github.com/sirupsen/logrus.Entry).Tracef does not support error-wrapping directive %w

Check failure on line 18 in environment/vm/lima/config.go

View workflow job for this annotation

GitHub Actions / build-linux

(*github.com/sirupsen/logrus.Entry).Tracef does not support error-wrapping directive %w

return obj
}

Expand Down
11 changes: 7 additions & 4 deletions environment/vm/lima/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func (l limaVM) Read(fileName string) (string, error) {
s, err := l.RunOutput("sudo", "cat", fileName)
if err != nil {
return "", fmt.Errorf("cannot read file: %s", fileName)
return "", fmt.Errorf("cannot read file '%s': %w", fileName, err)
}
return s, err
}
Expand Down Expand Up @@ -45,16 +45,15 @@ type fileInfo struct {
}

func newFileInfo(guest environment.GuestActions, filename string) (fileInfo, error) {
statErr := fmt.Errorf("cannot stat file: %s", filename)
info := fileInfo{}
// "%s,%a,%Y,%F" -> size, permission, modified time, type
stat, err := guest.RunOutput("sudo", "stat", "-c", "%s,%a,%Y,%F", filename)
if err != nil {
return info, statErr
return info, statError(filename, err)
}
stats := strings.Split(stat, ",")
if len(stats) < 4 {
return info, statErr
return info, statError(filename, err)
}
info.name = filename
info.size, _ = strconv.ParseInt(stats[0], 10, 64)
Expand All @@ -71,6 +70,10 @@ func newFileInfo(guest environment.GuestActions, filename string) (fileInfo, err
return info, nil
}

func statError(filename string, err error) error {
return fmt.Errorf("cannot stat file '%s': %w", filename, err)
}

// IsDir implements fs.FileInfo
func (f fileInfo) IsDir() bool { return f.isDir }

Expand Down

0 comments on commit 72dc9ae

Please sign in to comment.