{"record":{"id":"140105c04af653c0","repo":"hasura/graphql-engine","slug":"write-global-config-file-w","errorCode":null,"errorMessage":"write global config file: %w","messagePattern":"write global config file: %w","errorType":"exception","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"cli/global_config.go","lineNumber":161,"sourceCode":"\tif stderrors.Is(err, fs.ErrNotExist) {\n\t\t// file does not exist, teat as first run and create it\n\t\tec.Logger.Debug(\n\t\t\t\"global config file does not exist, this could be the first run, creating it...\",\n\t\t)\n\n\t\t// create an empty config object\n\t\tgc := &rawGlobalConfig{}\n\n\t\t// populate the keys\n\t\terr := gc.validateKeys()\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"setup global config object: %w\", err))\n\t\t}\n\n\t\t// write the file\n\t\terr = gc.write(ec.GlobalConfigFile)\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"write global config file: %w\", err))\n\t\t}\n\n\t\tec.Logger.Debugf(\n\t\t\t\"global config file written at '%s' with content '%v'\",\n\t\t\tec.GlobalConfigFile,\n\t\t\tgc,\n\t\t)\n\n\t\t// also show a notice about telemetry\n\t\tec.Logger.Info(TelemetryNotice)\n\t} else if stderrors.Is(err, fs.ErrExist) || err == nil {\n\t\t// file exists, verify contents\n\t\tec.Logger.Debug(\"global config file exists, verifying contents\")\n\n\t\t// initialize the config object\n\t\tgc := rawGlobalConfig{}\n\n\t\terr := gc.read(ec.GlobalConfigFile)","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/global_config.go#L143-L179","documentation":"During first-run initialization, gc.write(ec.GlobalConfigFile) failed after the empty config object was successfully created and validated. It is a plain disk I/O failure writing the marshaled YAML/JSON — the same class as error 210, but occurring on the create-new-file path rather than the rewrite path.","triggerScenarios":"Fresh install where the config file does not yet exist and the directory exists but is not writable (MkdirAll with os.ModePerm can succeed on a dir that is still not writable for the invoking user, e.g. sticky-bit or umask interactions), or a read-only filesystem.","commonSituations":"First run in a container, first run as a user without write access to the config dir created by an installer (root-owned ~/.<app>), or antivirus/mandatory locking on Windows blocking file creation.","solutions":["chmod/chown the config directory so the invoking user can create files in it","Pre-create the config file manually with valid content so initialization skips writing","Move GlobalConfigDir to a writable path","On Windows, check AV/EDR is not locking the config path"],"exampleFix":"# before\n$ mycli setup  # fails on first run\n# after\n$ sudo chown -R $(id -u):$(id -g) ~/.mycli\n$ mycli setup","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(ec.GlobalConfigFile); errors.Is(err, os.ErrNotExist) {\n    if err := os.WriteFile(ec.GlobalConfigFile, []byte(\"uuid: \\\"\\\"\\ncli_environment: \\\"\\\"\\n\"), 0o644); err != nil {\n        return fmt.Errorf(\"cannot pre-seed config file: %w\", err)\n    }\n}","typeGuard":"func canCreateFileIn(dir string) bool {\n    f, err := os.CreateTemp(dir, \".probe\")\n    if err != nil {\n        return false\n    }\n    _ = f.Close()\n    _ = os.Remove(f.Name())\n    return true\n}","tryCatchPattern":"if err := ec.Prepare(ctx); err != nil {\n    if strings.Contains(err.Error(), \"write global config file\") && ec.GlobalConfigFile != \"\" {\n        ec.GlobalConfigFile = filepath.Join(os.TempDir(), GlobalConfigFileName)\n        return ec.Prepare(ctx)\n    }\n    return err\n}","preventionTips":["Pre-seed a minimal valid config file during provisioning","Ensure the invoking user owns the config directory before first run","Use writable mounts for config in containers"],"tags":["go","filesystem","permissions","first-run","config"],"backgroundTag":"file-write-permission-denied","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}