{"record":{"id":"89d057a24a966f0d","repo":"henrygd/beszel","slug":"failed-to-create-smartctl-directory-w","errorCode":null,"errorMessage":"failed to create smartctl directory: %w","messagePattern":"failed to create smartctl directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/smart_windows.go","lineNumber":26,"sourceCode":"\t\"os\"\n\t\"path/filepath\"\n\t\"sync\"\n)\n\n//go:embed smartmontools/smartctl.exe\nvar embeddedSmartctl []byte\n\nvar (\n\tsmartctlOnce sync.Once\n\tsmartctlPath string\n\tsmartctlErr  error\n)\n\nfunc ensureEmbeddedSmartctl() (string, error) {\n\tsmartctlOnce.Do(func() {\n\t\tdestDir := filepath.Join(os.TempDir(), \"beszel\", \"smartmontools\")\n\t\tif err := os.MkdirAll(destDir, 0o755); err != nil {\n\t\t\tsmartctlErr = fmt.Errorf(\"failed to create smartctl directory: %w\", err)\n\t\t\treturn\n\t\t}\n\n\t\tdestPath := filepath.Join(destDir, \"smartctl.exe\")\n\t\tif err := os.WriteFile(destPath, embeddedSmartctl, 0o755); err != nil {\n\t\t\tsmartctlErr = fmt.Errorf(\"failed to write embedded smartctl: %w\", err)\n\t\t\treturn\n\t\t}\n\n\t\tsmartctlPath = destPath\n\t})\n\n\treturn smartctlPath, smartctlErr\n}\n","sourceCodeStart":8,"sourceCodeEnd":41,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/agent/smart_windows.go#L8-L41","documentation":"Thrown by ensureEmbeddedSmartctl in agent/smart_windows.go when os.MkdirAll fails to create the temp extraction directory %TEMP%\\\\beszel\\\\smartmontools where the bundled smartctl.exe is written at runtime. It wraps the underlying OS error (e.g. permission denied, disk full, read-only volume). Until this succeeds, no embedded smartctl path is available and SMART data collection is skipped.","triggerScenarios":"Calling agent SMART collection on Windows; smartctlOnce runs once and os.MkdirAll fails because the temp directory cannot be created or accessed.","commonSituations":"TMP/TEMP env vars point to a non-writable or read-only location; antivirus or endpoint protection blocks creating executables under the user temp dir; disk full; running as a service account whose temp dir is restricted.","solutions":["Verify TMP/TEMP point to a writable directory and that the user can create folders there","Check disk free space and file-system permissions on the temp volume","Exclude %TEMP%\\\\beszel from antivirus/EDR write blocking or relocate temp via TMP env var for the agent process","Check the wrapped %w cause: it names the exact OS reason (permission, path not found, etc.)"],"exampleFix":"// before\nif err := os.MkdirAll(destDir, 0o755); err != nil {\n\treturn fmt.Errorf(\"failed to create smartctl directory: %w\", err)\n}\n// after\nif err := os.MkdirAll(destDir, 0o755); err != nil {\n\tlog.Warn().Err(err).Str(\"dir\", destDir).Msg(\"smartctl dir creation failed; SMART disabled\")\n\treturn nil // degrade gracefully instead of failing SMART collection\n}","handlingStrategy":"validation","validationCode":"info, err := os.Stat(os.TempDir())\nif err != nil || !info.IsDir() {\n\treturn fmt.Errorf(\"temp dir %s unusable: %w\", os.TempDir(), err)\n}\nprobe := filepath.Join(os.TempDir(), \"beszel\", \"smartmontools\")\nif err := os.MkdirAll(probe, 0o755); err != nil {\n\treturn fmt.Errorf(\"cannot create smartctl dir: %w\", err)\n}","typeGuard":"func hasWritableTempDir() bool {\n\tf, err := os.CreateTemp(\"\", \"beszel-probe-*\")\n\tif err != nil {\n\t\treturn false\n\t}\n\tf.Close()\n\tos.Remove(f.Name())\n\treturn true\n}","tryCatchPattern":"path, err := ensureEmbeddedSmartctl()\nif err != nil {\n\tvar perr *fs.PathError\n\tif errors.As(err, &perr) {\n\t\tlog.Printf(\"smartctl unavailable (%s: %v); SMART monitoring disabled\", perr.Op, perr.Err)\n\t}\n\treturn nil // degrade gracefully\n}","preventionTips":["Ensure TMP/TEMP point to a writable, non-read-only directory","Whitelist the agent's temp paths in antivirus/EDR policies","Monitor disk free space on machines running the agent","Run the agent under an account with write access to its temp dir"],"tags":["windows","filesystem","smartctl"],"backgroundTag":"temp-directory-not-writable","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}