hasura/graphql-engine · error · errors.Error
error finding absolute path for project directory: %w
Error message
error finding absolute path for project directory: %w
What it means
Thrown by validateDirectory when filepath.Abs fails to convert the configured execution directory into an absolute path. This wraps the underlying stdlib error and means the CLI cannot establish a canonical working directory before validating the project layout. In practice it almost never fires on healthy systems since Abs only fails when os.Getwd fails.
Source
Thrown at cli/directory.go:40
// 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))
}
return errors.E(op, fmt.Errorf("error getting directory details: %w", err))
}
if !ed.IsDir() {
return errors.E(op, fmt.Errorf("'%s' is not a directory: %w", ed.Name(), err))
}
// config.yaml
// migrations/View on GitHub (pinned to 724551b9ae)
Solutions
- Verify the directory you're running from still exists (pwd or ls .); recreate it or cd elsewhere and retry
- Pass an explicit absolute --directory/project flag so Abs does not depend on the process cwd
- Check for scripts or CI steps that delete the working directory before invoking the CLI
Example fix
# before ./mycli --dir ./project run # run from a deleted cwd # after cd /tmp && ./mycli --dir /home/user/project run
Defensive patterns
Strategy: validation
Validate before calling
dir := os.Getenv("PROJECT_DIR")
abs, err := filepath.Abs(dir)
if err != nil {
log.Fatalf("cannot resolve %q to an absolute path: %v", dir, err)
}
if _, err := os.Stat(abs); err != nil {
log.Fatalf("execution directory unusable: %v", err)
} Try / catch
if err := ec.Validate(); err != nil {
if strings.Contains(err.Error(), "error finding absolute path") {
// cwd or path resolution is broken; re-run from an existing directory with an absolute path
}
return err
} Prevention
- Always pass an absolute directory path to the CLI in scripts and CI
- Avoid running commands from directories that build scripts might delete
- Fail fast in wrappers: verify cwd exists before invoking the tool
When it happens
Trigger: Calling Validate (or any CLI command that triggers it) with ec.ExecutionDirectory set to a relative path while the process's current working directory has been deleted or become unreadable, causing filepath.Abs -> os.Getwd to return an error.
Common situations: Running the CLI from a terminal whose cwd was deleted (e.g. after a build script rm -rf's its own directory), in containers where the workdir was removed, or after a branch switch removed the current directory.
Related errors
- failed to get the absolute fullPath of %q: %w
- writing metadata to file: %w
- reading metadata file: %w
- error getting current working directory: %w
- did not find required directory. use 'init'?: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/33be19fa109febd1.
Report an issue: GitHub.