siyuan-note/siyuan · critical

rollback [ ] to [ ] failed

Error message

rollback [%s] to [%s] failed: %w

What it means

When a rename in the legacy iOS workspace migration fails midway, the function rolls back every already-completed move in reverse order. If any rollback rename also fails, the failure is recorded as 'rollback [%s] to [%s] failed' and joined (errors.Join) with the original failure, so the caller sees both the abort cause and the partial-migration state. The workspace may be left with some entries moved and some not.

Solutions

  1. Read the joined error chain: fix the FIRST 'move ... failed' cause first, then manually move back any entries listed in 'rollback ... failed'
  2. Close processes holding files in the workspace directories (sync clients, editors, backup tools) and re-run so a fresh migration completes
  3. Manually restore the reported paths (rename [to] back to [from]) to return to the legacy layout, then restart the app to retry migration
  4. Ensure sufficient free disk space and volume health before retrying
Defensive patterns

Strategy: try-catch

Validate before calling

if err := migrateLegacyIOSWorkspace(...); err != nil {
    if errors.Is(err, os.ErrPermission) {
        return fmt.Errorf("close other apps holding the workspace and retry: %w", err)
    }
    // enumerate joined rollback errors and restore paths manually
    for _, sub := range errors.Errors(err) {
        logging.LogErrorf("partial migration entry: %v", sub)
    }
}

Type guard

func rollbackFailures(err error) []error {
    var out []error
    for _, sub := range errors.Errors(err) {
        if strings.Contains(sub.Error(), "rollback ") {
            out = append(out, sub)
        }
    }
    return out
}

Try / catch

if err := migrateLegacyIOSWorkspace(...); err != nil {
    joined := errors.Errors(err)
    logging.LogErrorf("migration aborted: %v (rollback failures: %d)", joined[0], len(joined)-1)
    // workspace may be partially migrated — reconcile manually before retry
    return err
}

Prevention

When it happens

Trigger: migrateLegacyIOSWorkspace successfully renamed one or more entries into defaultWorkspaceDir, a later os.Rename fails, and the compensating os.Rename(completedMove.to, completedMove.from) for a previously completed move itself errors (locked file, permission change, destination recreated mid-rollback).

Common situations: A file inside a moved directory is open/locked by another process (cloud-sync client, indexer, antivirus) during rollback; the original source location was recreated by another component mid-migration; disk full or transient I/O error on the volume; iOS app suspended mid-write.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/6c39c915c0ed9c21. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/working_mobile.go:200

		}

		to := filepath.Join(defaultWorkspaceDir, name)
		if _, statErr := os.Lstat(to); statErr == nil {
			return false, fmt.Errorf("destination [%s] already exists", to)
		} else if !errors.Is(statErr, fs.ErrNotExist) {
			return false, fmt.Errorf("stat destination [%s] failed: %w", to, statErr)
		}
		moves = append(moves, workspaceDirMove{from: from, to: to})
	}

	var completed []workspaceDirMove
	for _, move := range moves {
		if renameErr := os.Rename(move.from, move.to); renameErr != nil {
			var rollbackErrors []error
			for i := len(completed) - 1; 0 <= i; i-- {
				completedMove := completed[i]
				if rollbackErr := os.Rename(completedMove.to, completedMove.from); rollbackErr != nil {
					rollbackErrors = append(rollbackErrors, fmt.Errorf("rollback [%s] to [%s] failed: %w",
						completedMove.to, completedMove.from, rollbackErr))
				}
			}
			return false, errors.Join(append([]error{fmt.Errorf("move [%s] to [%s] failed: %w", move.from, move.to, renameErr)}, rollbackErrors...)...)
		}
		completed = append(completed, move)
	}

	for _, move := range completed {
		logging.LogInfof("moved legacy iOS workspace dir [from=%s, to=%s]", move.from, move.to)
	}
	return true, nil
}

func replaceLegacyIOSWorkspacePath(workspacePaths []string, workspaceBaseDir, defaultWorkspaceDir string) []string {
	for i, workspacePath := range workspacePaths {
		if filepath.Clean(workspacePath) == filepath.Clean(workspaceBaseDir) {
			workspacePaths[i] = defaultWorkspaceDir

View on GitHub (pinned to 9f775e8a12)