{"record":{"id":"d1f325236f224f28","repo":"hasura/graphql-engine","slug":"failed-writing-current-time-to-file-w","errorCode":null,"errorMessage":"failed writing current time to file: %w","messagePattern":"failed writing current time to file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli/update/auto_update.go","lineNumber":35,"sourceCode":"\tlastUpdateCheckTime, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn time.Time{}\n\t}\n\n\ttimeInFile, err := time.Parse(timeLayout, string(lastUpdateCheckTime))\n\tif err != nil {\n\t\treturn time.Time{}\n\t}\n\n\treturn timeInFile\n}\n\nfunc writeTimeToFile(path string, inputTime time.Time) error {\n\tvar op errors.Op = \"update.writeTimeToFile\"\n\n\terr := os.WriteFile(path, []byte(inputTime.Format(timeLayout)), 0o644)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"failed writing current time to file: %w\", err))\n\t}\n\n\treturn nil\n}\n\n// ShouldRunCheck checks the file f for a timestamp and returns true\n// if the last update check was >= autoCheckInterval .\nfunc ShouldRunCheck(f string) bool {\n\tlastUpdateTime := getTimeFromFileIfExists(f)\n\n\treturn time.Since(lastUpdateTime) >= autoCheckInterval\n}\n","sourceCodeStart":17,"sourceCodeEnd":48,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/update/auto_update.go#L17-L48","documentation":"writeTimeToFile persists the 'last update check' timestamp using os.WriteFile and wraps any failure. It fails when the path (typically the update-check timestamp file in the CLI config directory) cannot be written - permission denied, a missing parent directory, a read-only filesystem, or a path that exists as a directory.","triggerScenarios":"Calling writeTimeToFile when the CLI config directory (e.g. ~/.hasura/) does not exist yet, is not writable, or the timestamp file path points at a directory or a file owned by another user (often after sudo usage).","commonSituations":"Running the CLI as a different user than the one that owns ~/.hasura (root vs user mismatch from earlier sudo runs), read-only or sandboxed home directories in containers/CI, or a stale directory in place of the timestamp file.","solutions":["Check ownership/permissions of the config directory and its update-check file; chown if a sudo run created root-owned files","Ensure the parent directory exists before writing (mkdir -p the config dir)","If the filesystem is read-only (container), disable update checks or point config to a writable path"],"exampleFix":"// before\nerr := writeTimeToFile(path, time.Now())\n\n// after\nif err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { return err }\nerr := writeTimeToFile(path, time.Now())","handlingStrategy":"try-catch","validationCode":"dir := filepath.Dir(path)\nif _, err := os.Stat(dir); os.IsNotExist(err) {\n    if err := os.MkdirAll(dir, 0o755); err != nil { /* handle */ }\n}","typeGuard":null,"tryCatchPattern":"if err := writeTimeToFile(path, now); err != nil {\n    // update timestamp is best-effort; log and continue\n    log.Printf(\"could not persist update-check time: %v\", err)\n}","preventionTips":["Pre-create the config directory at CLI startup","Avoid mixing sudo and regular user runs so config files stay user-owned"],"tags":["update-check","filesystem","permissions","hasura-cli"],"backgroundTag":"file-write-permission-denied","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}