{"record":{"id":"d89472c1d4e8209d","repo":"siyuan-note/siyuan","slug":"read-master-password-migration-failed-w","errorCode":null,"errorMessage":"read master password migration failed: %w","messagePattern":"read master password migration failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":562,"sourceCode":"\t\treturn fmt.Errorf(\"marshal master password migration failed: %w\", err)\n\t}\n\treturn filelock.WriteFile(p, data)\n}\n\nfunc readMasterPasswordMigration() (*masterPasswordMigration, error) {\n\tmasterPasswordMigrationMu.Lock()\n\tdefer masterPasswordMigrationMu.Unlock()\n\treturn readMasterPasswordMigrationUnlocked()\n}\n\nfunc readMasterPasswordMigrationUnlocked() (*masterPasswordMigration, error) {\n\tp := masterPasswordMigrationPath()\n\tif !filelock.IsExist(p) {\n\t\treturn nil, nil\n\t}\n\tdata, err := filelock.ReadFile(p)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read master password migration failed: %w\", err)\n\t}\n\tvar m masterPasswordMigration\n\tif err = gulu.JSON.UnmarshalJSON(data, &m); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal master password migration failed: %w\", err)\n\t}\n\treturn &m, nil\n}\n\nfunc removeMasterPasswordMigration() {\n\tmasterPasswordMigrationMu.Lock()\n\tdefer masterPasswordMigrationMu.Unlock()\n\tremoveMasterPasswordMigrationUnlocked()\n}\n\nfunc removeMasterPasswordMigrationUnlocked() {\n\tp := masterPasswordMigrationPath()\n\tif err := filelock.Remove(p); err != nil && !os.IsNotExist(err) {\n\t\tlogging.LogErrorf(\"remove master password migration failed: %s\", err)","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/crypto.go#L544-L580","documentation":"readMasterPasswordMigrationUnlocked could not read the existing master password migration file from disk via filelock.ReadFile. The migration state cannot be loaded, so callers (readMasterPasswordMigration, removeMasterPasswordMigrationBox) receive this wrapped error instead of the record.","triggerScenarios":"The migration file exists (filelock.IsExist returned true) but opening/reading it fails — permission denied, file locked by another process, or I/O error on the disk.","commonSituations":"File owned by another user after restoring a data directory, the file locked by antivirus or a sync client (OneDrive/Dropbox), or hardware/disk I/O errors.","solutions":["Fix file permissions on the migration file so the kernel process can read it","Close processes locking the file (sync clients, antivirus, second SiYuan instance)","Check disk health / OS event logs for I/O errors","If the file is unrecoverable, restore it from backup or re-run the migration; note the existing record cannot be authenticated-read","Verify the file is not a directory or symlink pointing outside the workspace"],"exampleFix":"// before: unreadable migration file\n-rw------- root root migration.json\n// after\nsudo chown $USER migration.json\nm, err := readMasterPasswordMigration()","handlingStrategy":"try-catch","validationCode":"p := masterPasswordMigrationPath()\nif fi, err := os.Stat(p); err == nil && fi.Mode().Perm()&0400 == 0 {\n    return fmt.Errorf(\"migration file not readable by current user\")\n}","typeGuard":null,"tryCatchPattern":"m, err := readMasterPasswordMigration()\nif err != nil {\n    if os.IsPermission(errors.Unwrap(err)) {\n        // prompt: fix file ownership/permissions\n    }\n    return err // do not treat unreadable existing state as 'no migration'\n}","preventionTips":["Keep migration file permissions readable by the kernel process user","Exclude the data directory from antivirus/sync clients that hold file locks","Check disk health if read errors recur","Preserve ownership when copying data directories between machines (use rsync -a or chown afterward)"],"tags":["go","filesystem","file-read","migration"],"backgroundTag":"file-read-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}