siyuan-note/siyuan · error
stat source [ ] failed
Error message
stat source [%s] failed: %w
What it means
For each legacy iOS workspace entry, migrateLegacyIOSWorkspace calls os.Lstat on the source path. If stat fails for a reason other than not-exist (skipped intentionally), it returns "stat source [<path>] failed: <cause>".
Solutions
- Check the wrapped cause for permission vs I/O errors
- Restore sandbox file access permissions for the app container
- Remove or repair the broken legacy entry that fails to stat
- Retry migration after device storage becomes healthy
Example fix
// before
return false, fmt.Errorf("stat source [%s] failed: %w", from, statErr)
// after: log and skip unreadable entries instead of aborting the whole migration
logging.LogErrorf("stat source [%s] failed: %v", from, statErr)
continue Defensive patterns
Strategy: try-catch
Validate before calling
// stat each legacy entry and report unreadable ones up front
for _, name := range legacyEntries {
if _, err := os.Lstat(filepath.Join(base, name)); err != nil && !os.IsNotExist(err) {
// resolve permissions/IO before migrating
}
} Try / catch
migrated, err := migrateLegacyIOSWorkspace(...)
if err != nil && strings.HasPrefix(err.Error(), "stat source") {
// restore file access, repair or skip the offending entry, then retry
} Prevention
- Preserve app sandbox file-access entitlements across updates
- Avoid modifying legacy workspace entries during migration
- Back up legacy entries before running migration
When it happens
Trigger: A legacy entry exists but cannot be statted — permission denied in the sandbox, broken symlink resolution, or I/O errors on the container volume.
Common situations: OS revoked file access after an update, corrupted legacy directory entries, files locked by another process during iOS backup/restore.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- stat destination [ ] failed
- move [ ] to [ ] failed
- read destination [ ] failed
- rollback [ ] to [ ] failed
- destination [ ] already exists
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/075febb6165065f0.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/working_mobile.go:181
}
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)
} 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 {View on GitHub (pinned to 9f775e8a12)