hasura/graphql-engine · error

error getting current working directory: %w

Error message

error getting current working directory: %w

What it means

os.Getwd() failed inside `hasura init`. The CLI resolves the current working directory before computing absolute init paths; failure means the process CWD was deleted or is unreadable (ENOENT/EACCES).

Source

Thrown at cli/commands/init.go:185

	if o.Endpoint != "" && !o.GetMetadataMigrations && o.EC.IsTerminal {
		r, err := util.GetYesNoPrompt(
			fmt.Sprintf("Initialize project with metadata & migrations from %s ?", o.Endpoint),
		)
		if err != nil {
			return errors.E(op, fmt.Errorf("prompt exited: %w", err))
		}

		o.GetMetadataMigrations = r
	}

	if !o.EC.IsTerminal {
		o.GetMetadataMigrations = true
	}

	cwdir, err := os.Getwd()
	if err != nil {
		return errors.E(op, fmt.Errorf("error getting current working directory: %w", err))
	}

	initPath, err := filepath.Abs(o.InitDir)
	if err != nil {
		return errors.E(op, err)
	}

	if initPath == cwdir {
		// check if pwd is filesystem root
		err := cli.CheckFilesystemBoundary(cwdir)
		if err != nil {
			return errors.E(
				op,
				fmt.Errorf("can't initialise hasura project in filesystem root: %w", err),
			)
		}
		// check if the current directory is already a hasura project
		err = cli.ValidateDirectory(cwdir)

View on GitHub (pinned to 724551b9ae)

Solutions

  1. cd into an existing directory and re-run `hasura init`
  2. Verify the shell's CWD exists (pwd) and is traversable
  3. Check directory permissions on parent paths if access is denied
Defensive patterns

Strategy: validation

Validate before calling

if wd, err := os.Getwd(); err != nil {
    log.Fatal("working directory unavailable; cd to a valid dir")
}

Prevention

When it happens

Trigger: Running `hasura init` from a directory that has been deleted while the shell still points at it, or with insufficient permission to traverse the CWD path.

Common situations: Deleted terminal working directory (common after rm -rf of the dir you're in); container/sandbox oddities where CWD is unlinked; overly restrictive directory modes.

Related errors


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