hashicorp/nomad · error

cannot generate data path - %s

Error message

cannot generate data path - %s

What it means

configInstall expands the data directory path with c.winPaths.Expand (defaulting to the appdata data directory if unset). This error is returned when the data dir path cannot be resolved to a concrete Windows path. Nomad needs a valid data directory for the service to store state.

Source

Thrown at command/windows_service_install.go:261

	return nil
}

func (c *WindowsServiceInstallCommand) configInstall(opts *windowsInstallOpts) error {
	// If the config or data directory are unset, default them
	if opts.configDir == "" {
		opts.configDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, "config")
	}
	if opts.dataDir == "" {
		opts.dataDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, "data")
	}

	var err error
	if opts.configDir, err = c.winPaths.Expand(opts.configDir); err != nil {
		return fmt.Errorf("cannot generate configuration path - %s", err)
	}
	if opts.dataDir, err = c.winPaths.Expand(opts.dataDir); err != nil {
		return fmt.Errorf("cannot generate data path - %s", err)
	}

	// Ensure directories exist
	if err = c.winPaths.CreateDirectory(opts.configDir, true); err != nil {
		return fmt.Errorf("cannot create configuration directory - %s", err)
	}

	if err = c.winPaths.CreateDirectory(opts.dataDir, true); err != nil {
		return fmt.Errorf("cannot create data directory - %s", err)
	}

	// Check if any configuration files exist
	matches, _ := filepath.Glob(filepath.Join(opts.configDir, "*"))
	if len(matches) < 1 {
		f, err := os.Create(filepath.Join(opts.configDir, "config.hcl"))
		if err != nil {
			return fmt.Errorf("could not create default configuration file - %s", err)
		}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check the wrapped error message for the unresolved path
  2. Pass an absolute Windows path like C:\ProgramData\nomad\data
  3. Ensure any environment variables used in the path are defined
  4. Omit -data-dir to use the default winsvc data directory

Example fix

// before
nomad windows service install -data-dir "%NOMAD_DATA%"
// after
nomad windows service install -data-dir "C:\ProgramData\nomad\data"
Defensive patterns

Strategy: validation

Validate before calling

// Validate the data dir is an absolute Windows path before invoking
if !filepath.IsAbs(dataDir) || strings.Contains(dataDir, "%") || strings.HasPrefix(dataDir, "~") {
    return errors.New("data-dir must be a fully-qualified absolute Windows path")
}

Prevention

When it happens

Trigger: Running 'nomad windows service install' with a -data-dir value that Expand cannot resolve: unset environment variable embedded in the path, malformed/unexpandable syntax, or non-Windows path forms.

Common situations: Custom -data-dir using a %VAR% that is undefined; relative or ~-style paths not expandable in the service context; typos in drive letters (e.g. 'D:\' when D: doesn't exist).

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/345115b62d0313e7. Report an issue: GitHub.