{"record":{"id":"1cf986694510ad0c","repo":"hasura/graphql-engine","slug":"directory-s-already-exists","errorCode":null,"errorMessage":"directory '%s' already exists","messagePattern":"directory '(.+?)' already exists","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/init.go","lineNumber":238,"sourceCode":"\t\treturn errors.E(op, err)\n\t}\n\n\treturn nil\n}\n\n// create the execution directory.\nfunc (o *InitOptions) createExecutionDirectory() error {\n\tvar op errors.Op = \"commands.InitOptions.createExecutionDirectory\"\n\n\tif o.EC.ExecutionDirectory == \"\" {\n\t\to.EC.ExecutionDirectory = o.InitDir\n\t} else {\n\t\to.EC.ExecutionDirectory = filepath.Join(o.EC.ExecutionDirectory, o.InitDir)\n\t}\n\n\t// create the execution directory\n\tif _, err := os.Stat(o.EC.ExecutionDirectory); err == nil {\n\t\treturn errors.E(op, fmt.Errorf(\"directory '%s' already exists\", o.EC.ExecutionDirectory))\n\t}\n\n\terr := os.MkdirAll(o.EC.ExecutionDirectory, os.ModePerm)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"error creating setup directories: %w\", err))\n\t}\n\n\treturn nil\n}\n\n// createFiles creates files required by the CLI in the ExecutionDirectory.\nfunc (o *InitOptions) createFiles() error {\n\tvar op errors.Op = \"commands.InitOptions.createFiles\"\n\t// create the directory\n\terr := os.MkdirAll(filepath.Dir(o.EC.ExecutionDirectory), os.ModePerm)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"error creating setup directories: %w\", err))\n\t}","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/init.go#L220-L256","documentation":"createExecutionDirectory in `hasura init` found that the target execution directory already exists (os.Stat succeeded). The CLI will not overwrite an existing directory when scaffolding a new project.","triggerScenarios":"Running `hasura init myproject` (or init into a relative subdirectory) when ./myproject already exists on disk.","commonSituations":"Re-running init after a previous attempt; name collision with an existing folder; scripting that assumes init is idempotent.","solutions":["Choose a different project/directory name: `hasura init myproject-v2`","If the existing dir is disposable, remove it (rm -rf myproject) and re-run","Init into the current directory only when it's empty/not already a Hasura project (the CLI separately rejects existing Hasura projects)"],"exampleFix":"// before\nhasura init myproject  # ./myproject exists\n// after\nrm -rf ./myproject && hasura init myproject","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(targetDir); err == nil {\n    log.Fatalf(\"directory %s already exists; choose another name\", targetDir)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat init as non-idempotent: generate unique dir names in automation","Clean up failed init attempts before re-running"],"tags":["hasura","cli","init","directory-exists","filesystem"],"backgroundTag":"directory-already-exists","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}