hasura/graphql-engine · error
error getting current working directory: %w
Error message
error getting current working directory: %w
What it means
validateDirectory resolves the CLI execution directory: if none was given it calls os.Getwd, and if the process has no valid current working directory (e.g. it was deleted) this error is returned before any command runs.
Source
Thrown at cli/directory.go:31
)
// validateDirectory sets execution directory and validate it to see that or any
// of the parent directory is a valid project directory. A valid project
// directory contains the following:
// 1. migrations directory
// 2. config.yaml file
// 3. metadata.yaml (optional)
// If the current directory or any parent directory (upto filesystem root) is
// found to have these files, ExecutionDirectory is set as that directory.
func (ec *ExecutionContext) validateDirectory() error {
var (
op errors.Op = "cli.ExecutionContext.validateDirectory"
err error
)
if len(ec.ExecutionDirectory) == 0 {
cwd, err := os.Getwd()
if err != nil {
return errors.E(op, fmt.Errorf("error getting current working directory: %w", err))
}
ec.ExecutionDirectory = cwd
} else {
ec.ExecutionDirectory, err = filepath.Abs(ec.ExecutionDirectory)
if err != nil {
return errors.E(
op,
fmt.Errorf("error finding absolute path for project directory: %w", err),
)
}
}
ed, err := os.Stat(ec.ExecutionDirectory)
if err != nil {
if stderrors.Is(err, fs.ErrNotExist) {
return errors.E(op, fmt.Errorf("did not find required directory. use 'init'?: %w", err))
}View on GitHub (pinned to 724551b9ae)
Solutions
- cd into an existing directory (`cd ~`) and re-run the CLI from there
- Explicitly pass an execution directory (e.g. `hasura --project /path/to/project ...`) so Getwd is never needed
- In scripts, avoid running the CLI from temp dirs that may be deleted concurrently
Example fix
# before $ cd /tmp/removed-dir # dir deleted $ hasura metadata export # after $ cd ~/my-project && hasura metadata export # or: hasura --project ~/my-project metadata export
Defensive patterns
Strategy: validation
Validate before calling
// ensure cwd is valid, or pass --project explicitly
if _, err := os.Getwd(); err != nil {
_ = os.Chdir(os.Getenv("HOME"))
}
// better: always invoke with an explicit project dir
// hasura --project /path/to/project <cmd> Try / catch
if err := ec.Validate(); err != nil {
if strings.Contains(err.Error(), "current working directory") {
_ = os.Chdir("/tmp")
// retry with explicit --project
}
} Prevention
- Always pass --project in scripts instead of relying on cwd
- Avoid running the CLI from temp dirs that other jobs may delete
When it happens
Trigger: The hasura CLI was started from a directory that has since been deleted (cwd unlinked), or getwd otherwise fails due to permission changes on a parent directory. In automation contexts where the process cwd is removed mid-run.
Common situations: Shell sitting in a deleted directory (common after rm -rf of the project dir in a still-open terminal), containers where the workdir was removed, or scripts cd-ing into a temp dir that gets cleaned up.
Related errors
- unable to create directory: %w
- generating docs failed: %w
- error getting current working directory: %w
- directory '%s' already exists
- error creating setup directories: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/29e5b6a629abb241.
Report an issue: GitHub.