cloudflare/cloudflared · error
ErrCreatingTemporaryFile
ErrCreatingTemporaryFile
Error message
temporary file creation failed
What it means
ErrCreatingTemporaryFile is returned by diagnostic procedures (collectLogs, rawNetworkInformationWriter, jsonNetworkInformationWriter, createTaskReport) when os.Create on a file in os.TempDir() fails. The diagnostic pipeline writes logs, network dumps, and task reports to temporary files before zipping them; if that creation fails the diagnostic cannot proceed. The original os error is discarded, so only the sentinel is visible.
Source
Thrown at diagnostic/error.go:27
ErrManagedLogNotFound = errors.New("managed log directory not found")
// Error used when it is not possible to collect logs using the log configuration.
ErrLogConfigurationIsInvalid = errors.New("provided log configuration is invalid")
// Error used when parsing the fields of the output of collector.
ErrInsufficientLines = errors.New("insufficient lines")
// Error used when parsing the lines of the output of collector.
ErrInsuficientFields = errors.New("insufficient fields")
// Error used when given key is not found while parsing KV.
ErrKeyNotFound = errors.New("key not found")
// Error used when there is no disk volume information available.
ErrNoVolumeFound = errors.New("no disk volume information found")
// Error user when the base url of the diagnostic client is not provided.
ErrNoBaseURL = errors.New("no base url")
// Error used when no metrics server is found listening to the known addresses list (check [metrics.GetMetricsKnownAddresses]).
ErrMetricsServerNotFound = errors.New("metrics server not found")
// Error used when multiple metrics server are found listening to the known addresses list (check [metrics.GetMetricsKnownAddresses]).
ErrMultipleMetricsServerFound = errors.New("multiple metrics server found")
// Error used when a temporary file creation fails within the diagnostic procedure
ErrCreatingTemporaryFile = errors.New("temporary file creation failed")
)
View on GitHub (pinned to 2253eeeb25)
Solutions
- Check that os.TempDir() (or $TMPDIR) exists and is writable by the user running cloudflared.
- Free disk space on the volume holding the temp directory.
- Remove any conflicting file/directory at the temp path the diagnostic writes to.
- Set TMPDIR to a writable location before launching the diagnostic.
Example fix
// before
outputLogHandle, err := os.Create(filepath.Join(os.TempDir(), logFilename))
if err != nil {
return "", ErrCreatingTemporaryFile
}
// after
outputLogHandle, err := os.Create(filepath.Join(os.TempDir(), logFilename))
if err != nil {
return "", fmt.Errorf("%w: %v", ErrCreatingTemporaryFile, err)
} Defensive patterns
Strategy: validation
Validate before calling
tmp := os.TempDir()
if fi, err := os.Stat(tmp); err != nil || !fi.IsDir() {
return errors.New("temp directory unavailable")
}
if f, err := os.CreateTemp(tmp, "cfd-diag-*"); err != nil {
return fmt.Errorf("temp dir not writable: %w", err)
} else {
f.Close()
os.Remove(f.Name())
} Try / catch
out, err := diagnostic.RunDiagnostic(log, options)
if errors.Is(err, diagnostic.ErrCreatingTemporaryFile) {
return fmt.Errorf("diagnostic failed: cannot write to %s: %w", os.TempDir(), err)
} Prevention
- Ensure TMPDIR points to an existing, writable directory for the process user.
- Monitor disk space on the temp volume; dumps can be large.
- Run cloudflared diagnostics as a user with write access to the system temp directory.
- Wrap sentinel returns with the underlying os error to ease future debugging.
When it happens
Trigger: os.Create(filepath.Join(os.TempDir(), ...)) failing at diagnostic/diagnostic.go:140 (output log), diagnostic/diagnostic.go:242 (raw network dump), and in the JSON network writer and createTaskReport paths — e.g. unwritable TMPDIR, full disk, or the path existing as a directory.
Common situations: Read-only or full /tmp, TMPDIR pointing to a non-existent or permission-restricted directory, running under a sandboxed service account with no write access to the temp directory, or a stale file/dir collision at the target name.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- creating temporary log file %s: %w
- the argument path must be a directory
- cloudflared service is already installed at %s; if you are r
- The file-writing error is: %v / The delete tunnel error is:
- ErrManagedLogNotFound
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/b3c590b7041a7b87.
Report an issue: GitHub.