{"record":{"id":"6c39c915c0ed9c21","repo":"siyuan-note/siyuan","slug":"rollback-s-to-s-failed-w","errorCode":null,"errorMessage":"rollback [%s] to [%s] failed: %w","messagePattern":"rollback \\[(.+?)\\] to \\[(.+?)\\] failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"kernel/util/working_mobile.go","lineNumber":200,"sourceCode":"\t\t}\n\n\t\tto := filepath.Join(defaultWorkspaceDir, name)\n\t\tif _, statErr := os.Lstat(to); statErr == nil {\n\t\t\treturn false, fmt.Errorf(\"destination [%s] already exists\", to)\n\t\t} else if !errors.Is(statErr, fs.ErrNotExist) {\n\t\t\treturn false, fmt.Errorf(\"stat destination [%s] failed: %w\", to, statErr)\n\t\t}\n\t\tmoves = append(moves, workspaceDirMove{from: from, to: to})\n\t}\n\n\tvar completed []workspaceDirMove\n\tfor _, move := range moves {\n\t\tif renameErr := os.Rename(move.from, move.to); renameErr != nil {\n\t\t\tvar rollbackErrors []error\n\t\t\tfor i := len(completed) - 1; 0 <= i; i-- {\n\t\t\t\tcompletedMove := completed[i]\n\t\t\t\tif rollbackErr := os.Rename(completedMove.to, completedMove.from); rollbackErr != nil {\n\t\t\t\t\trollbackErrors = append(rollbackErrors, fmt.Errorf(\"rollback [%s] to [%s] failed: %w\",\n\t\t\t\t\t\tcompletedMove.to, completedMove.from, rollbackErr))\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false, errors.Join(append([]error{fmt.Errorf(\"move [%s] to [%s] failed: %w\", move.from, move.to, renameErr)}, rollbackErrors...)...)\n\t\t}\n\t\tcompleted = append(completed, move)\n\t}\n\n\tfor _, move := range completed {\n\t\tlogging.LogInfof(\"moved legacy iOS workspace dir [from=%s, to=%s]\", move.from, move.to)\n\t}\n\treturn true, nil\n}\n\nfunc replaceLegacyIOSWorkspacePath(workspacePaths []string, workspaceBaseDir, defaultWorkspaceDir string) []string {\n\tfor i, workspacePath := range workspacePaths {\n\t\tif filepath.Clean(workspacePath) == filepath.Clean(workspaceBaseDir) {\n\t\t\tworkspacePaths[i] = defaultWorkspaceDir","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/working_mobile.go#L182-L218","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Read the joined error chain: fix the FIRST 'move ... failed' cause first, then manually move back any entries listed in 'rollback ... failed'","Close processes holding files in the workspace directories (sync clients, editors, backup tools) and re-run so a fresh migration completes","Manually restore the reported paths (rename [to] back to [from]) to return to the legacy layout, then restart the app to retry migration","Ensure sufficient free disk space and volume health before retrying"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if err := migrateLegacyIOSWorkspace(...); err != nil {\n    if errors.Is(err, os.ErrPermission) {\n        return fmt.Errorf(\"close other apps holding the workspace and retry: %w\", err)\n    }\n    // enumerate joined rollback errors and restore paths manually\n    for _, sub := range errors.Errors(err) {\n        logging.LogErrorf(\"partial migration entry: %v\", sub)\n    }\n}","typeGuard":"func rollbackFailures(err error) []error {\n    var out []error\n    for _, sub := range errors.Errors(err) {\n        if strings.Contains(sub.Error(), \"rollback \") {\n            out = append(out, sub)\n        }\n    }\n    return out\n}","tryCatchPattern":"if err := migrateLegacyIOSWorkspace(...); err != nil {\n    joined := errors.Errors(err)\n    logging.LogErrorf(\"migration aborted: %v (rollback failures: %d)\", joined[0], len(joined)-1)\n    // workspace may be partially migrated — reconcile manually before retry\n    return err\n}","preventionTips":["Ensure only one SiYuan instance runs against the workspace during migration","Pause cloud-sync and backup clients while the app performs workspace migration","Keep adequate free disk space so back-to-back renames cannot fail with ENOSPC","On failure, follow the joined error chain to restore the listed [to] paths back to [from] before retrying"],"tags":["filesystem","migration","rollback","rename","ios"],"backgroundTag":"file-write-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}