cloudflare/cloudflared · error
creating temporary log file %s: %w
Error message
creating temporary log file %s: %w
What it means
Wrapped os.Create failure in diagnostic CopyFilesFromDirectory: the temporary merged log file (cloudflared.log in the OS temp dir) that individual rolling logs are concatenated into could not be created, so log collection aborts.
Source
Thrown at diagnostic/log_collector_utils.go:83
return NewLogInformation(outputHandle.Name(), true, false), nil
}
func CopyFilesFromDirectory(path string) (string, error) {
const defaultLogFilename = "cloudflared.log"
// rolling logs have as suffix the current date thus
// when iterating the path files they are already in
// chronological order
files, err := os.ReadDir(path)
if err != nil {
return "", fmt.Errorf("error reading directory %s: %w", path, err)
}
// nolint: gosec
outputHandle, err := os.Create(filepath.Join(os.TempDir(), logFilename))
if err != nil {
return "", fmt.Errorf("creating temporary log file %s: %w", logFilename, err)
}
defer func() { _ = outputHandle.Close() }()
for _, file := range files {
// nolint: gosec
logHandle, err := os.Open(filepath.Join(path, file.Name()))
if err != nil {
return "", fmt.Errorf("error opening file %s: %w", file.Name(), err)
}
_, err = io.Copy(outputHandle, logHandle)
_ = logHandle.Close()
if err != nil {
return "", fmt.Errorf("error copying file %s: %w", file.Name(), err)
}
}
// nolint: gosec
logHandle, err := os.Open(filepath.Join(path, defaultLogFilename))View on GitHub (pinned to 2253eeeb25)
Solutions
- Check disk space and write permissions on os.TempDir() (TMPDIR)
- Free space or point TMPDIR at a writable location
- Re-run the diagnostic collection
Example fix
// before TMPDIR=/ro/mount cloudflared diagnostic collect // after TMPDIR=/var/tmp cloudflared diagnostic collect
Defensive patterns
Strategy: try-catch
Validate before calling
if err := checkWritable(os.TempDir()); err != nil { os.Setenv("TMPDIR", "/var/tmp") } Try / catch
out, err := diagnostic.CopyFilesFromDirectory(ctx, fs, logDir, logFilename)
if err != nil && strings.Contains(err.Error(), "creating temporary log file") {
return fmt.Errorf("cannot write temp logs: %w — check disk space/TMPDIR", err)
} Prevention
- Ensure /tmp (or TMPDIR) is writable and has headroom
- Avoid read-only tmpfs in containers used for diagnostics
- Clean stale temp files periodically
When it happens
Trigger: os.Create(filepath.Join(os.TempDir(), logFilename)) fails: /tmp is full, read-only, or the process lacks write permission; TMPDIR points somewhere invalid.
Common situations: Containers with read-only /tmp or tiny tmpfs; restrictive TMPDIR; disk-quota exhaustion during diagnostics.
Understand the failure class
Background: "Permission denied" / "Failed to write" file errors: why a library can't write its files to disk (EACCES, EPERM, ENOSPC) and how to fix them — this error's family across 43 libraries.
Related errors
- ErrManagedLogNotFound
- ErrCreatingTemporaryFile
- error reading directory %s: %w
- error opening file %s: %w
- error copying file %s: %w
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/72698687bf544ac3.
Report an issue: GitHub.