GoogleContainerTools/skaffold · error
unable to create temp directory %q: %w
Error message
unable to create temp directory %q: %w
What it means
The logfile package builds a path under a temp/log root by joining escaped path segments, then creates the parent directory with 0700 permissions via os.MkdirAll before opening the log file. This error wraps the MkdirAll failure, meaning the directory for the log file could not be created. The wrapped OS error (permission denied, path exists as file, disk full) is the real cause.
Source
Thrown at pkg/skaffold/logfile/logfile.go:35
package logfile
import (
"fmt"
"os"
"path/filepath"
"regexp"
)
// Create creates or truncates a file to be used to output logs.
func Create(path ...string) (*os.File, error) {
logfile := filepath.Join(os.TempDir(), "skaffold")
for _, p := range path {
logfile = filepath.Join(logfile, escape(p))
}
dir := filepath.Dir(logfile)
if err := os.MkdirAll(dir, 0700); err != nil {
return nil, fmt.Errorf("unable to create temp directory %q: %w", dir, err)
}
return os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
}
var escapeRegexp = regexp.MustCompile(`[^a-zA-Z0-9-_.]`)
func escape(s string) string {
return escapeRegexp.ReplaceAllString(s, "-")
}
View on GitHub (pinned to a1189de023)
Solutions
- Check the OS error in the message: if 'permission denied', chown/chmod the target directory or run with a user that can write there
- If a non-directory exists at the path, remove/rename the offending file
- Point logging at a writable location (adjust XDG_CACHE_HOME / TMPDIR or run with a writable --kubeconfig-agnostic cache path)
- Verify the filesystem is writable (not read-only mount) and has free space
Example fix
// before: cache dir not writable $ skaffold dev // error: unable to create temp directory "/home/user/.cache/skaffold": mkdir ...: permission denied // after $ sudo chown -R $(whoami) ~/.cache/skaffold || export XDG_CACHE_HOME=/tmp/cache
Defensive patterns
Strategy: validation
Validate before calling
// ensure the log root is writable before invoking Create
root := logRoot() // e.g. ~/.cache/skaffold
if fi, err := os.Stat(root); err == nil && !fi.IsDir() {
return fmt.Errorf("%s exists and is not a directory; remove it", root)
}
if err := os.MkdirAll(root, 0700); err != nil {
return fmt.Errorf("log root %s not writable: %w", root, err)
} Try / catch
lf, err := logfile.Create(path...)
if err != nil && strings.Contains(err.Error(), "unable to create temp directory") {
// fall back to an OS temp dir
alt := filepath.Join(os.TempDir(), "skaffold-logs")
os.MkdirAll(alt, 0700)
lf, err = logfile.CreateWithRoot(alt, path...)
} Prevention
- Run skaffold as a user with write access to the cache/temp dirs, or fix ownership with chown
- Do not place files where directory names will be created (e.g. a file named 'skaffold' under .cache)
- Point XDG_CACHE_HOME/TMPDIR at writable volumes in containers or read-only rootfs setups
- Watch disk space; MkdirAll also fails on full or failing filesystems
When it happens
Trigger: os.MkdirAll(dir, 0700) fails: parent path component is a regular file, read-only filesystem, permission denied, path too long, or disk errors.
Common situations: Running skaffold as a user without write access to the temp/cache directory; SKAFFOLD/xdg cache dir pointing at a read-only mount; a previous file named like the directory; containers running with read-only rootfs.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- writing %q to %q: %w
- reading .dockerignore: %w
- walking workspace: %w
- unable to stat file %q: %w
- failed to create directory: %v
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/abfc8865d7fccccc.
Report an issue: GitHub.