siyuan-note/siyuan · error

read destination [ ] failed

Error message

read destination [%s] failed: %w

What it means

migrateLegacyIOSWorkspace in kernel/util/working_mobile.go moves legacy iOS workspace entries into <workspaceBaseDir>/siyuan. It first lists the destination directory; if os.ReadDir fails, it returns "read destination [<dir>] failed: <cause>".

Solutions

  1. Verify the default workspace directory exists and is readable by the app
  2. Ensure the parent workspaceBaseDir is accessible in the sandbox container
  3. Recreate the default workspace directory if it was deleted
  4. Re-run migration after app storage permissions are restored

Example fix

// before
if readErr != nil {
	return false, fmt.Errorf("read destination [%s] failed: %w", defaultWorkspaceDir, readErr)
}
// after: tolerate a not-yet-created destination
if readErr != nil {
	if !errors.Is(readErr, fs.ErrNotExist) {
		return false, fmt.Errorf("read destination [%s] failed: %w", defaultWorkspaceDir, readErr)
	}
	// destination missing means empty; proceed to create it
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check destination readability before migration
dir := filepath.Join(workspaceBaseDir, "siyuan")
if _, err := os.ReadDir(dir); err != nil && !os.IsNotExist(err) {
	// fix container access before migrating
}

Try / catch

migrated, err := migrateLegacyIOSWorkspace(...)
if err != nil && strings.HasPrefix(err.Error(), "read destination") {
	// ensure sandbox file access; retry after permissions restored
}

Prevention

When it happens

Trigger: The default workspace directory <workspaceBaseDir>/siyuan cannot be read — it does not exist and cannot be created/read, or an I/O error occurs during the directory listing.

Common situations: iOS container paths changed by the OS, sandbox permission changes after an app update, the default workspace directory being removed mid-migration.

Related errors


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

Appendix: source

Thrown at kernel/util/working_mobile.go:168

	from string
	to   string
}

func migrateLegacyIOSWorkspace(workspaceBaseDir string) (migrated bool, err error) {
	if ContainerIOS != Container || !gulu.File.IsDir(workspaceBaseDir) {
		return false, nil
	}

	for _, name := range []string{"conf", "data", "temp"} {
		if !gulu.File.IsDir(filepath.Join(workspaceBaseDir, name)) {
			return false, nil
		}
	}

	defaultWorkspaceDir := filepath.Join(workspaceBaseDir, "siyuan")
	destinationEntries, readErr := os.ReadDir(defaultWorkspaceDir)
	if readErr != nil {
		return false, fmt.Errorf("read destination [%s] failed: %w", defaultWorkspaceDir, readErr)
	}
	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)

View on GitHub (pinned to 9f775e8a12)