hasura/graphql-engine · error

rename new to exe: %w

Error message

rename new to exe: %w

What it means

In ApplyUpdate's swap sequence, the current binary was successfully renamed to '<exe>.old' but the following os.Rename(newExe, exe) failed (cli/update/update.go:185). The code attempts to roll back by restoring the old binary; if rollback succeeds this exact error is returned (the installation is consistent again), and if rollback fails you get error 495 instead.

Source

Thrown at cli/update/update.go:185

	// rename the new binary as the current binary
	err = os.Rename(newExe, exe)
	if err != nil {
		// rename unsuccessful
		//
		// The filesystem is now in a bad state. We have successfully
		// moved the existing binary to a new location, but we couldn't move the new
		// binary to take its place. That means there is no file where the current executable binary
		// used to be!
		// Try to rollback by restoring the old binary to its original path.
		rerr := os.Rename(oldExe, exe)
		if rerr != nil {
			// rolling back failed, ask user to re-install cli
			return errors.E(op, fmt.Errorf(
				"rename old to exe: inconsistent state, re-install cli: %w",
				rerr))
		}
		// rolled back, throw update error
		return errors.E(op, fmt.Errorf("rename new to exe: %w", err))
	}

	// rename success, remove the old binary
	errRemove := os.Remove(oldExe)

	// windows has trouble removing old binaries, so hide it instead
	// it will be removed next time this code runs.
	if errRemove != nil {
		_ = hideFile(oldExe)
	}

	return nil
}

// Returns an absolute path that can be used to
// re-invoke the current program.
func getExecutablePath() (string, error) {
	execPath, err := os.Executable()

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Your installation was rolled back — verify the old binary works (cli --version), then fix the cause (permissions/antivirus) and retry the update.
  2. On Windows, exclude the install directory from antivirus and close other instances of the CLI before updating.
  3. Check the '.<exe>.new' file exists and is executable after the failure; delete leftovers before retrying.
  4. If it recurs, update manually: download the release binary and replace the file yourself.

Example fix

# before
$ cli update
# error: rename new to exe: file in use

# after
$ (close all cli instances / disable AV realtime scan)
$ rm -f /usr/local/bin/.cli.new /usr/local/bin/cli.old
$ cli update
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := os.Stat(newExe); err != nil {
    return fmt.Errorf("downloaded binary missing before swap: %s", newExe)
}

Try / catch

if err := update.ApplyUpdate(v); err != nil {
    if strings.Contains(err.Error(), "rename new to exe") && !strings.Contains(err.Error(), "inconsistent") {
        // rollback succeeded; current binary is still the old working one
        log.Printf("update rolled back, still on previous version: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: ApplyUpdate where the downloaded '.<exe>.new' file cannot be renamed over the exe path: destination locked by another process, .new file removed/quarantined, or permission changed after the first rename.

Common situations: Windows file locking (running process or antivirus holds the exe path); the .new binary being flagged and quarantined; running the update from a shell whose working state interferes with the swap.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/0a03822a0bb5bbb9. Report an issue: GitHub.