{"record":{"id":"2319f2ea6e77965e","repo":"henrygd/beszel","slug":"failed-to-create-update-data-directory-w","errorCode":null,"errorMessage":"failed to create update data directory: %w","messagePattern":"failed to create update data directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/ghupdate/ghupdate.go","lineNumber":143,"sourceCode":"\t\treturn false, err\n\t}\n\n\tcurrentVersion := semver.MustParse(strings.TrimPrefix(p.currentVersion, \"v\"))\n\tnewVersion := semver.MustParse(strings.TrimPrefix(latest.Tag, \"v\"))\n\n\tif newVersion.LTE(currentVersion) {\n\t\tColorPrintf(ColorGreen, \"You already have the latest version %s.\", p.currentVersion)\n\t\treturn false, nil\n\t}\n\n\tsuffix := archiveSuffix(p.config.ArchiveExecutable, runtime.GOOS, runtime.GOARCH, buildGOARM)\n\tasset, err := latest.findAssetBySuffix(suffix)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\n\tif err := os.MkdirAll(p.config.DataDir, 0755); err != nil {\n\t\treturn false, fmt.Errorf(\"failed to create update data directory: %w\", err)\n\t}\n\treleaseDir, err := os.MkdirTemp(p.config.DataDir, \".beszel_update-\")\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to create update directory: %w\", err)\n\t}\n\tdefer os.RemoveAll(releaseDir)\n\n\tColorPrintf(ColorYellow, \"Downloading %s...\", asset.Name)\n\n\t// download the release asset\n\tassetPath, err := archivePath(releaseDir, asset.Name)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tif err := downloadFile(p.config.Context, p.config.HttpClient, asset.DownloadUrl, assetPath, p.config.UseMirror); err != nil {\n\t\treturn false, err\n\t}\n\tColorPrint(ColorYellow, \"Verifying checksum...\")","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/ghupdate/ghupdate.go#L125-L161","documentation":"Before staging the download, update() creates Config.DataDir (defaulting to os.TempDir()) recursively with os.MkdirAll. If that fails — permission denied, read-only filesystem, path is a file, etc. — the error is wrapped with this message. No download happens until a writable data directory exists.","triggerScenarios":"ghupdate.Update -> update when os.MkdirAll(DataDir, 0755) fails: DataDir points at a path the running user cannot create, an existing file occupies the path, or the filesystem is read-only.","commonSituations":"Running the agent as an unprivileged user while DataDir is owned by root; DataDir set to a path inside a read-only container layer; a regular file accidentally exists at the DataDir path; SELinux/AppArmor denial.","solutions":["Create the directory manually with correct ownership: `sudo mkdir -p <DataDir> && sudo chown <user> <DataDir>`.","Point Config.DataDir at a writable location for the user running the process (e.g. /var/lib/beszel owned by the service user).","Check that the path isn't an existing regular file and the filesystem isn't mounted read-only (`mount | grep <path>`).","Review SELinux/AppArmor audit logs if permissions look correct but creation still fails."],"exampleFix":"// before\nUpdate(ghupdate.Config{DataDir: \"/root/.beszel\"}) // running as non-root\n// after\nUpdate(ghupdate.Config{DataDir: \"/home/deploy/.beszel\"})","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(cfg.DataDir, 0755); err != nil {\n    return fmt.Errorf(\"pre-flight: cannot create DataDir %q: %w\", cfg.DataDir, err)\n}\nif fi, err := os.Stat(cfg.DataDir); err != nil || !fi.IsDir() {\n    return errors.New(\"DataDir path exists but is not a directory\")\n}","typeGuard":null,"tryCatchPattern":"updated, err := ghupdate.Update(cfg)\nif err != nil && strings.Contains(err.Error(), \"failed to create update data directory\") {\n    log.Printf(\"DataDir %q is not creatable (%v); fix ownership/mount or choose a writable path\", cfg.DataDir, err)\n}","preventionTips":["Pre-create DataDir at deploy time with the service user as owner.","Never point DataDir at a read-only mount, container image layer, or a regular file path.","Verify writability in your service's health/startup checks."],"tags":["filesystem","permissions","mkdir","configuration"],"backgroundTag":"permission-denied","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}