{"record":{"id":"b792385e412fe523","repo":"henrygd/beszel","slug":"failed-to-create-temp-directory-w","errorCode":null,"errorMessage":"failed to create temp directory: %w","messagePattern":"failed to create temp directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/sensors_windows.go","lineNumber":60,"sourceCode":"\n//go:embed all:lhm/bin/Release/net48\nvar lhmFs embed.FS\n\nvar (\n\tbeszelLhm     *lhmProcess\n\tbeszelLhmOnce sync.Once\n\tuseLHM        = os.Getenv(\"LHM\") == \"true\"\n)\n\nvar errNoSensors = errors.New(\"no sensors found (try running as admin with LHM=true)\")\n\n// newlhmProcess copies the embedded LHM executable to a temporary directory and starts it.\nfunc newlhmProcess() (*lhmProcess, error) {\n\tdestDir := filepath.Join(os.TempDir(), \"beszel\")\n\texecPath := filepath.Join(destDir, \"beszel_lhm.exe\")\n\n\tif err := os.MkdirAll(destDir, 0755); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create temp directory: %w\", err)\n\t}\n\n\t// Only copy if executable doesn't exist\n\tif _, err := os.Stat(execPath); os.IsNotExist(err) {\n\t\tif err := copyEmbeddedDir(lhmFs, \"lhm/bin/Release/net48\", destDir); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to copy embedded directory: %w\", err)\n\t\t}\n\t}\n\n\tlhm := &lhmProcess{\n\t\texecPath: execPath,\n\t\ttempDir:  destDir,\n\t}\n\n\tif err := lhm.startProcess(); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to start process: %w\", err)\n\t}\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/agent/sensors_windows.go#L42-L78","documentation":"On Windows the agent's LibreHardwareMonitor (LHM) helper requires copying its embedded executable to a temp directory; this error wraps an os.MkdirAll failure for %TEMP%\\beszel. It indicates the temp directory could not be created — filesystem or permission problem — so no sensor data can be collected via LHM.","triggerScenarios":"newlhmProcess() builds destDir = os.TempDir()+\"beszel\" and calls os.MkdirAll(destDir, 0755); failure (ENOENT parent gone, EPERM, disk full, path redirected to a read-only location) wraps the OS error.","commonSituations":"TEMP/TMP env var pointing at a missing, read-only, or network path; enterprise policy restricting executable creation in temp; disk full; temp cleaner service removing the directory mid-run; agent running as a service account without write access to its temp dir.","solutions":["Check TEMP/TMP env vars for the account running the agent and ensure the path exists and is writable.","Free disk space if the volume holding %TEMP% is full.","Run the agent service under an account with write permission to its temp directory, or set TEMP to a dedicated writable folder.","Exclude the beszel temp dir from antivirus/temp-cleaner policies that delete it.","Create the directory manually (mkdir %TEMP%\\beszel) and re-run to confirm permissions."],"exampleFix":"// before (service env)\nTEMP=C:\\Windows\\Temp  # service account lacks write access\n// after\nset TEMP=C:\\beszel\\tmp  (grant the service account Modify on it)","handlingStrategy":"try-catch","validationCode":"// before starting LHM helper:\nif err := os.MkdirAll(filepath.Join(os.TempDir(), \"beszel\"), 0755); err != nil {\n    return fmt.Errorf(\"temp dir unusable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"proc, err := newlhmProcess()\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to create temp directory\") {\n        slog.Warn(\"LHM unavailable: temp dir not writable\", \"err\", err)\n        return nil // run without LHM sensor data\n    }\n    return err\n}","preventionTips":["Ensure the agent's service account has write access to %TEMP%","Set TEMP/TMP to a dedicated writable path for service deployments","Exclude the temp dir from antivirus and temp-cleaner policies","Monitor disk space on the volume hosting %TEMP%"],"tags":["windows","sensors","filesystem","temp-directory"],"backgroundTag":"temp-directory-create-failed","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}