hasura/graphql-engine · error

cannot write config file: %w

Error message

cannot write config file: %w

What it means

`hasura init` failed to write the generated config.yaml via o.EC.WriteConfig after scaffolding the config object. Wrapped error typically indicates an OS-level write failure or serialization problem in the execution directory.

Source

Thrown at cli/commands/init.go:287

	if o.Endpoint != "" {
		if _, err := url.ParseRequestURI(o.Endpoint); err != nil {
			return errors.E(op, fmt.Errorf("error validating endpoint URL: %w", err))
		}

		config.Endpoint = o.Endpoint
	}

	if o.AdminSecret != "" {
		config.AdminSecret = o.AdminSecret
	}

	// write the config file
	o.EC.Config = config
	o.EC.ConfigFile = filepath.Join(o.EC.ExecutionDirectory, "config.yaml")

	err = o.EC.WriteConfig(nil)
	if err != nil {
		return errors.E(op, fmt.Errorf("cannot write config file: %w", err))
	}

	// create migrations directory
	o.EC.MigrationDir = filepath.Join(o.EC.ExecutionDirectory, cli.DefaultMigrationsDirectory)

	err = os.MkdirAll(o.EC.MigrationDir, os.ModePerm)
	if err != nil {
		return errors.E(op, fmt.Errorf("cannot write migration directory: %w", err))
	}

	if config.Version >= cli.V2 {
		// create metadata directory
		o.EC.MetadataDir = filepath.Join(o.EC.ExecutionDirectory, cli.DefaultMetadataDirectory)

		err = os.MkdirAll(o.EC.MetadataDir, os.ModePerm)
		if err != nil {
			return errors.E(op, fmt.Errorf("cannot write metadata directory: %w", err))
		}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Check write access and free space in the init directory
  2. Remove partially-created project and re-run init cleanly
  3. Ensure no other process holds/locks config.yaml
Defensive patterns

Strategy: validation

Validate before calling

// ensure config.yaml path is writable
f := filepath.Join(executionDir, "config.yaml")
if _, err := os.OpenFile(f, os.O_WRONLY|os.O_CREATE, 0o644); err != nil {
    log.Fatal("config.yaml not writable: ", err)
}

Prevention

When it happens

Trigger: Execution directory became unwritable, disk full, or the config could not be marshalled/written to <dir>/config.yaml during init.

Common situations: Read-only project mount in a container; disk quota; antivirus/locking on config.yaml; concurrent init runs writing the same path.

Related errors


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