henrygd/beszel · error

create dir: %w

Error message

create dir: %w

What it means

Thrown by downloadFile in the fetchsmartctl build tool when os.MkdirAll fails to create the parent directory of the download destination. It is a wrapped OS error from the codegen/update tool that fetches smartmontools binaries. The download aborts before any HTTP request is made.

Source

Thrown at agent/tools/fetchsmartctl/main.go:47

		fatalf("-url and -out are required")
	}

	if !*force {
		if info, err := os.Stat(*out); err == nil && info.Size() > 0 {
			fmt.Println("smartctl.exe already present, skipping download")
			return
		}
	}

	if err := downloadFile(*url, *out, *sha); err != nil {
		fatalf("download failed: %v", err)
	}
}

func downloadFile(url, dest, shaHex string) error {
	// Prepare destination
	if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
		return fmt.Errorf("create dir: %w", err)
	}

	// HTTP client
	client := &http.Client{Timeout: 60 * time.Second}
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		return fmt.Errorf("new request: %w", err)
	}
	req.Header.Set("User-Agent", "beszel-fetchsmartctl/1.0")

	resp, err := client.Do(req)
	if err != nil {
		return fmt.Errorf("http get: %w", err)
	}
	defer resp.Body.Close()

	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return fmt.Errorf("unexpected HTTP status: %s", resp.Status)

View on GitHub (pinned to b38fb7dafa)

Solutions

  1. Check the wrapped %w OS error for the exact cause
  2. Verify the destination path's parent is not an existing file and is writable
  3. Run the tool from a writable checkout (not read-only CI volume) and free disk space if needed
  4. Create the directory manually and re-run to isolate permissions
Defensive patterns

Strategy: validation

Validate before calling

parent := filepath.Dir(dest)
if info, err := os.Stat(parent); err == nil && !info.IsDir() {
	return fmt.Errorf("%s exists and is not a directory", parent)
}
if err := os.MkdirAll(parent, 0o755); err != nil {
	return err
}

Try / catch

if err := downloadFile(url, dest, sha); err != nil {
	var perr *fs.PathError
	if errors.As(err, &perr) && perr.Op == "mkdir" {
		fmt.Printf("fix permissions on %s: %v\n", filepath.Dir(dest), perr.Err)
	}
	os.Exit(1)
}

Prevention

When it happens

Trigger: Running the fetchsmartctl tool (go generate / go run) and the destination's parent directory cannot be created or accessed.

Common situations: Output path (-o flag or default) points to a read-only source tree; typo'd path segment collides with an existing regular file; running without write permission in repo dir; disk full.

Related errors


AI-assisted analysis of henrygd/beszel@b38fb7dafa (2026-08-31). Data as JSON: /api/errors/220f6d3d9d52c312. Report an issue: GitHub.