{"record":{"id":"55102c705207ffdd","repo":"henrygd/beszel","slug":"failed-to-write-embedded-smartctl-w","errorCode":null,"errorMessage":"failed to write embedded smartctl: %w","messagePattern":"failed to write embedded smartctl: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/smart_windows.go","lineNumber":32,"sourceCode":"var 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":14,"sourceCodeEnd":41,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/agent/smart_windows.go#L14-L41","documentation":"Thrown by ensureEmbeddedSmartctl when os.WriteFile fails to write the embedded smartctl.exe binary into the temp directory. This wraps the OS write error (permission denied, disk full, path locked). The extracted executable is how the agent provides smartctl without a separate install.","triggerScenarios":"os.WriteFile(destPath, embeddedSmartctl, 0o755) fails after the directory was created successfully — typically because writing or setting exec permission on smartctl.exe is denied.","commonSituations":"Antivirus quarantines or locks the freshly written smartctl.exe; file already exists as a locked running process; disk full; FAT/exFAT volumes ignoring or rejecting exec permission bits.","solutions":["Delete a stale/locked smartctl.exe in %TEMP%\\\\beszel\\\\smartmontools and restart the agent","Check the wrapped %w OS error for the exact cause (access denied vs disk full)","Exclude the path from antivirus real-time scanning or quarantine rules","Ensure the agent user has write+execute permission on the temp directory"],"exampleFix":"// before\nif err := os.WriteFile(destPath, embeddedSmartctl, 0o755); err != nil {\n\treturn fmt.Errorf(\"failed to write embedded smartctl: %w\", err)\n}\n// after\nif err := os.WriteFile(destPath, embeddedSmartctl, 0o755); err != nil {\n\tos.Remove(destPath) // clear possibly locked/quarantined stale binary\n\treturn fmt.Errorf(\"failed to write embedded smartctl to %s: %w\", destPath, err)\n}","handlingStrategy":"try-catch","validationCode":"dir := filepath.Join(os.TempDir(), \"beszel\", \"smartmontools\")\nprobe, err := os.CreateTemp(dir, \".probe-*\")\nif err == nil {\n\tprobe.Close()\n\tos.Remove(probe.Name())\n}","typeGuard":null,"tryCatchPattern":"path, err := ensureEmbeddedSmartctl()\nif err != nil {\n\tif strings.Contains(err.Error(), \"write embedded smartctl\") {\n\t\tos.Remove(filepath.Join(os.TempDir(), \"beszel\", \"smartmontools\", \"smartctl.exe\"))\n\t}\n\treturn fmt.Errorf(\"SMART disabled: %w\", err)\n}","preventionTips":["Exclude %TEMP%\\\\beszel from antivirus real-time scanning","Remove stale smartctl.exe before restarting the agent","Check free disk space before deployment","Prefer NTFS over FAT/exFAT for the temp volume so exec permissions behave"],"tags":["windows","filesystem","smartctl"],"backgroundTag":"file-write-permission-denied","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}