Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: log possible error while reading config file #1240

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Trace(fmt.Errorf("error reading config file: %w", err))

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
Loading