hasura/graphql-engine · warning
failed writing current time to file: %w
Error message
failed writing current time to file: %w
What it means
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.
Source
Thrown at cli/update/auto_update.go:35
lastUpdateCheckTime, err := os.ReadFile(path)
if err != nil {
return time.Time{}
}
timeInFile, err := time.Parse(timeLayout, string(lastUpdateCheckTime))
if err != nil {
return time.Time{}
}
return timeInFile
}
func writeTimeToFile(path string, inputTime time.Time) error {
var op errors.Op = "update.writeTimeToFile"
err := os.WriteFile(path, []byte(inputTime.Format(timeLayout)), 0o644)
if err != nil {
return errors.E(op, fmt.Errorf("failed writing current time to file: %w", err))
}
return nil
}
// ShouldRunCheck checks the file f for a timestamp and returns true
// if the last update check was >= autoCheckInterval .
func ShouldRunCheck(f string) bool {
lastUpdateTime := getTimeFromFileIfExists(f)
return time.Since(lastUpdateTime) >= autoCheckInterval
}
View on GitHub (pinned to 724551b9ae)
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
Example fix
// before
err := writeTimeToFile(path, time.Now())
// after
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { return err }
err := writeTimeToFile(path, time.Now()) Defensive patterns
Strategy: try-catch
Validate before calling
dir := filepath.Dir(path)
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, 0o755); err != nil { /* handle */ }
} Try / catch
if err := writeTimeToFile(path, now); err != nil {
// update timestamp is best-effort; log and continue
log.Printf("could not persist update-check time: %v", err)
} Prevention
- Pre-create the config directory at CLI startup
- Avoid mixing sudo and regular user runs so config files stay user-owned
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- creating metadata file %s failed: %w
- creating target migrations directory: %w
- creating target seeds directory: %w
- creating new binary file: %w
- error generating codegen for action %s: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/d1f325236f224f28.
Report an issue: GitHub.