{"record":{"id":"29e5b6a629abb241","repo":"hasura/graphql-engine","slug":"error-getting-current-working-directory-w-29e5b6","errorCode":null,"errorMessage":"error getting current working directory: %w","messagePattern":"error getting current working directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/directory.go","lineNumber":31,"sourceCode":")\n\n// validateDirectory sets execution directory and validate it to see that or any\n// of the parent directory is a valid project directory. A valid project\n// directory contains the following:\n// 1. migrations directory\n// 2. config.yaml file\n// 3. metadata.yaml (optional)\n// If the current directory or any parent directory (upto filesystem root) is\n// found to have these files, ExecutionDirectory is set as that directory.\nfunc (ec *ExecutionContext) validateDirectory() error {\n\tvar (\n\t\top  errors.Op = \"cli.ExecutionContext.validateDirectory\"\n\t\terr error\n\t)\n\tif len(ec.ExecutionDirectory) == 0 {\n\t\tcwd, err := os.Getwd()\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"error getting current working directory: %w\", err))\n\t\t}\n\n\t\tec.ExecutionDirectory = cwd\n\t} else {\n\t\tec.ExecutionDirectory, err = filepath.Abs(ec.ExecutionDirectory)\n\t\tif err != nil {\n\t\t\treturn errors.E(\n\t\t\t\top,\n\t\t\t\tfmt.Errorf(\"error finding absolute path for project directory: %w\", err),\n\t\t\t)\n\t\t}\n\t}\n\n\ted, err := os.Stat(ec.ExecutionDirectory)\n\tif err != nil {\n\t\tif stderrors.Is(err, fs.ErrNotExist) {\n\t\t\treturn errors.E(op, fmt.Errorf(\"did not find required directory. use 'init'?: %w\", err))\n\t\t}","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/directory.go#L13-L49","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n$ cd /tmp/removed-dir  # dir deleted\n$ hasura metadata export\n# after\n$ cd ~/my-project && hasura metadata export\n# or: hasura --project ~/my-project metadata export","handlingStrategy":"validation","validationCode":"// ensure cwd is valid, or pass --project explicitly\nif _, err := os.Getwd(); err != nil {\n    _ = os.Chdir(os.Getenv(\"HOME\"))\n}\n// better: always invoke with an explicit project dir\n// hasura --project /path/to/project <cmd>","typeGuard":null,"tryCatchPattern":"if err := ec.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"current working directory\") {\n        _ = os.Chdir(\"/tmp\")\n        // retry with explicit --project\n    }\n}","preventionTips":["Always pass --project in scripts instead of relying on cwd","Avoid running the CLI from temp dirs that other jobs may delete"],"tags":["hasura","cli","filesystem","cwd","working-directory"],"backgroundTag":"current-working-directory-removed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}