GoogleContainerTools/skaffold · error
getting last log file %w
Error message
getting last log file %w
What it means
SaveLastLog calls lastLogFile(fp) to resolve the path of the log file to write. When the caller passes an empty path, lastLogFile falls back to ~/.skaffold/last.log via homedir.Dir(); if that resolution fails, this error wraps the cause. The save cannot proceed because no destination path could be determined.
Source
Thrown at pkg/skaffold/event/v2/event.go:347
return fmt.Errorf("marshalling event: %w", err)
}
if _, err := f.WriteString(contents.String() + "\n"); err != nil {
return fmt.Errorf("writing string: %w", err)
}
}
handler.logLock.Unlock()
return nil
}
// SaveLastLog writes the output from the previous run to the specified filepath
func SaveLastLog(fp string) error {
handler.logLock.Lock()
defer handler.logLock.Unlock()
// Create file to write logs to
fp, err := lastLogFile(fp)
if err != nil {
return fmt.Errorf("getting last log file %w", err)
}
// Ensure that the filepath provided has the directories available when attemping to save the file.
dir := filepath.Dir(fp)
if err := os.MkdirAll(dir, 0700); err != nil {
return fmt.Errorf("unable to create directory %q: %w", dir, err)
}
f, err := os.OpenFile(fp, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
return fmt.Errorf("opening %s: %w", fp, err)
}
defer f.Close()
// Iterate over events, grabbing contents only from SkaffoldLogEvents
var contents bytes.Buffer
for _, ev := range handler.eventLog {
if sle := ev.GetSkaffoldLogEvent(); sle != nil {
// Strip ansi color sequences as this makes it easier to deal with when pasting into github issues
if _, err = contents.WriteString(stripansi.Strip(sle.Message)); err != nil {View on GitHub (pinned to a1189de023)
Solutions
- Pass an explicit filepath argument to SaveLastLog instead of relying on the ~/.skaffold/last.log default.
- Set the HOME environment variable to a writable directory for the running process.
- Check that the OS user has a valid home directory entry (getent passwd $(whoami)).
Example fix
// before
err := event.SaveLastLog("")
// after
err := event.SaveLastLog(filepath.Join(os.TempDir(), "skaffold-last.log")) Defensive patterns
Strategy: fallback
Validate before calling
if os.Getenv("HOME") == "" && runtime.GOOS != "windows" {
return errors.New("HOME is unset; pass an explicit path to SaveLastLog")
} Try / catch
if err := event.SaveLastLog(""); err != nil {
if strings.Contains(err.Error(), "getting last log file") {
return event.SaveLastLog(filepath.Join(os.TempDir(), "last.log"))
}
return err
} Prevention
- Always pass an explicit path in containerized/cron environments
- Ensure HOME is set in the process environment
- Verify the OS user has a valid home directory
When it happens
Trigger: Calling SaveLastLog("") (or via TestSaveLastLog) on a system where homedir.Dir() fails — HOME unset, no passwd entry for the user, or the home directory resolution library erroring.
Common situations: Running skaffold in a minimal container or cron job with no HOME env var; running as a system user without a home directory; Windows profile redirection issues.
Related errors
- retrieving home directory: %w
- retrieving home directory: %w
- retrieving home directory: %w
- value must be one of `always`, `missing`, or `never`
- CONFIG_REMOTE_REPO_CACHE_NOT_FOUND_ERR
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/c1cc031bb07656a0.
Report an issue: GitHub.