siyuan-note/siyuan · error

stat destination [ ] failed

Error message

stat destination [%s] failed: %w

What it means

During legacy iOS workspace migration, each known legacy directory is checked with os.Lstat before being renamed into the new default workspace. If the Lstat fails with an error other than NotExist (the destination already existing is handled separately), migration aborts and wraps the stat error with the destination path. This guards against ambiguous filesystem states where the mover cannot tell whether the destination is safe to write.

Solutions

  1. Check the wrapped statErr (%w) to identify the underlying cause (permission, I/O, symlink loop) and fix that condition
  2. Verify the app has read permission on the new workspace directory and its parents; repair with chown/chmod or reinstall the app container
  3. If a stale entry sits at the destination, remove or rename it manually, then relaunch so migration re-runs
  4. If the volume is failing or unmountable, restore the workspace from sync/backup to a healthy location

Example fix

// before: migration aborts on unexpected stat error
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)
}
// after: pre-check the parent directory is traversable before migrating
if dirErr := os.Chdir(filepath.Dir(to)); dirErr != nil {
    logging.LogErrorf("workspace dir [%s] not accessible: %v", filepath.Dir(to), dirErr)
    return false, dirErr
}
Defensive patterns

Strategy: try-catch

Validate before calling

for _, name := range knownEntries {
    to := filepath.Join(defaultWorkspaceDir, name)
    if _, err := os.Lstat(to); err == nil {
        // destination already exists — resolve manually before launching
        continue
    } else if !errors.Is(err, fs.ErrNotExist) {
        // pre-flight: parent must be statable and writable
        if _, derr := os.Stat(filepath.Dir(to)); derr != nil {
            return fmt.Errorf("workspace dir [%s] not accessible: %w", filepath.Dir(to), derr)
        }
    }
}

Type guard

func statProblem(err error) bool {
    return err != nil && !errors.Is(err, fs.ErrNotExist)
}

Try / catch

moved, err := migrateLegacyIOSWorkspace(...)
if err != nil {
    var statErr *fs.PathError
    if errors.As(err, &statErr) {
        logging.LogErrorf("check permissions/path of [%s]: %v", statErr.Path, statErr.Err)
    }
    return err
}

Prevention

When it happens

Trigger: migrateLegacyIOSWorkspace calls os.Lstat(to) for a destination path under defaultWorkspaceDir and the returned error is neither nil (exists) nor fs.ErrNotExist — e.g. a permission error on a parent directory of the destination, an I/O error, or a symlink loop in the path.

Common situations: Restored or partially synced workspace where the destination path exists but is unreadable; macOS/iOS app-container permission changes after an OS upgrade; a corrupted or locked parent directory on the volume; antivirus or backup software holding the directory open.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at kernel/util/working_mobile.go:188

	if 0 < len(destinationEntries) {
		return false, fmt.Errorf("destination [%s] is not empty", defaultWorkspaceDir)
	}

	var moves []workspaceDirMove
	for _, name := range legacyIOSWorkspaceEntries {
		from := filepath.Join(workspaceBaseDir, name)
		if _, statErr := os.Lstat(from); statErr != nil {
			if errors.Is(statErr, fs.ErrNotExist) {
				continue
			}
			return false, fmt.Errorf("stat source [%s] failed: %w", from, statErr)
		}

		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)

View on GitHub (pinned to 9f775e8a12)