{"record":{"id":"cb8085f7dafe4ec0","repo":"hasura/graphql-engine","slug":"operation-failed-w-cb8085","errorCode":null,"errorMessage":"operation failed: %w","messagePattern":"operation failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/init.go","lineNumber":366,"sourceCode":"func (o *InitOptions) Run() error {\n\tvar op errors.Op = \"commands.InitOptions.Run\"\n\n\tcontext := &initCtx{\n\t\tec:      o.EC,\n\t\tinitOps: o,\n\t\tlogger:  o.EC.Logger,\n\t\terr:     nil,\n\t}\n\n\tconfigInitFSM := newInitFSM()\n\n\terr := configInitFSM.SendEvent(createProjectDirectory, context)\n\tif err != nil {\n\t\treturn errors.E(op, err)\n\t}\n\n\tif configInitFSM.Current == failedOperation {\n\t\treturn errors.E(op, fmt.Errorf(\"operation failed: %w\", context.err))\n\t}\n\n\treturn nil\n}\n\nconst (\n\tcreatingProjectDirectory stateType = \"Creating project directory\"\n\tfailedCreatingProjectDir stateType = \"Failed to create project directory\"\n\tvalidatingEndpoint       stateType = \"Validating Endpoint\"\n\tfailedValidatingEndpoint stateType = \"Failed validating endpoint\"\n\texportingMetadata        stateType = \"Exporting Metadata\"\n\tfailedExportingMetadata  stateType = \"Failed to export Metadata\"\n\tcreatingMigration        stateType = \"Creating Migration\"\n\tfailedCreatingMigration  stateType = \"Failed creating Migration\"\n\tendState                 stateType = \"End State\"\n)\n\nconst (","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/init.go#L348-L384","documentation":"Init FSM failure: after SendEvent(createProjectDirectory) the state machine is in failedOperation, so the stored context.err (from createExecutionDirectory/createFiles) is wrapped as 'operation failed'. This aggregates the per-step init failures described in errors 49-57.","triggerScenarios":"`hasura init` where directory creation or file scaffolding fails — existing directory, permission denial, read-only FS, invalid endpoint URL, or config write failure.","commonSituations":"Non-idempotent automation re-running `hasura init` into an existing folder; CI containers with restricted mounts; invalid --endpoint values.","solutions":["Read the wrapped context.err to find the failing step and apply the matching fix (existing dir, permissions, URL validity)","Pre-check the target directory (writable, non-existent, not already a Hasura project) before init in scripts","Re-run init after cleaning the failed target directory"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight the whole init\nif _, err := os.Stat(target); err == nil { log.Fatal(\"target exists\") }\nif _, err := url.ParseRequestURI(endpoint); endpoint != \"\" && err != nil { log.Fatal(\"bad endpoint\") }\nif err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil { log.Fatal(err) }","typeGuard":null,"tryCatchPattern":"if err := initCmd.Run(); err != nil {\n    var inner error\n    if errors.As(err, &inner) { log.Printf(\"init step failed: %v\", inner) }\n    // remediate (dir exists / perms / URL) then retry\n}","preventionTips":["Pre-check target dir, permissions, and endpoint before init","Make automation idempotent: unique dirs or cleanup before init"],"tags":["hasura","cli","init","fsm","project-setup"],"backgroundTag":"project-init-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}