hasura/graphql-engine · error

directory '%s' already exists

Error message

directory '%s' already exists

What it means

createExecutionDirectory in `hasura init` found that the target execution directory already exists (os.Stat succeeded). The CLI will not overwrite an existing directory when scaffolding a new project.

Source

Thrown at cli/commands/init.go:238

		return errors.E(op, err)
	}

	return nil
}

// create the execution directory.
func (o *InitOptions) createExecutionDirectory() error {
	var op errors.Op = "commands.InitOptions.createExecutionDirectory"

	if o.EC.ExecutionDirectory == "" {
		o.EC.ExecutionDirectory = o.InitDir
	} else {
		o.EC.ExecutionDirectory = filepath.Join(o.EC.ExecutionDirectory, o.InitDir)
	}

	// create the execution directory
	if _, err := os.Stat(o.EC.ExecutionDirectory); err == nil {
		return errors.E(op, fmt.Errorf("directory '%s' already exists", o.EC.ExecutionDirectory))
	}

	err := os.MkdirAll(o.EC.ExecutionDirectory, os.ModePerm)
	if err != nil {
		return errors.E(op, fmt.Errorf("error creating setup directories: %w", err))
	}

	return nil
}

// createFiles creates files required by the CLI in the ExecutionDirectory.
func (o *InitOptions) createFiles() error {
	var op errors.Op = "commands.InitOptions.createFiles"
	// create the directory
	err := os.MkdirAll(filepath.Dir(o.EC.ExecutionDirectory), os.ModePerm)
	if err != nil {
		return errors.E(op, fmt.Errorf("error creating setup directories: %w", err))
	}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Choose a different project/directory name: `hasura init myproject-v2`
  2. If the existing dir is disposable, remove it (rm -rf myproject) and re-run
  3. Init into the current directory only when it's empty/not already a Hasura project (the CLI separately rejects existing Hasura projects)

Example fix

// before
hasura init myproject  # ./myproject exists
// after
rm -rf ./myproject && hasura init myproject
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(targetDir); err == nil {
    log.Fatalf("directory %s already exists; choose another name", targetDir)
}

Prevention

When it happens

Trigger: Running `hasura init myproject` (or init into a relative subdirectory) when ./myproject already exists on disk.

Common situations: Re-running init after a previous attempt; name collision with an existing folder; scripting that assumes init is idempotent.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/1cf986694510ad0c. Report an issue: GitHub.