{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L544-L580","documentation":"readMasterPasswordMigrationUnlocked reads the persisted master-password migration file (if it exists) via filelock.ReadFile and wraps any read error as 'read master password migration failed'. A missing file is treated as success (nil, nil), so this error means the file exists but could not be read — e.g. permissions, locking conflicts, or I/O errors.","triggerScenarios":"filelock.ReadFile(p) returns an error in readMasterPasswordMigration or removeMasterPasswordMigrationBox: permission denied on an existing migration file, file locked by another process beyond filelock's tolerance, I/O error from failing storage, or the path being a directory.","commonSituations":"Migration file owned by another user after switching run accounts; second kernel instance or sync tool holding a conflicting lock; disk errors on the workspace volume; path unexpectedly created as a directory by tooling.","solutions":["Check and fix permissions/ownership of the migration file under the workspace data directory","Stop other kernel instances or sync/backup tools that may hold the file lock, then retry","If the path is a directory or the file is unreadable and no migration is in progress, move it aside (keep a copy for recovery) and retry","Check disk health (dmesg/SMART) if I/O errors persist"],"exampleFix":"// diagnose\nls -l <workspace>/data/<migration-file>\nfuser -v <workspace>/data/<migration-file>\n// fix\nsudo chown <user> <workspace>/data/<migration-file> && chmod u+rw <workspace>/data/<migration-file>","handlingStrategy":"try-catch","validationCode":"p := masterPasswordMigrationPath()\nif filelock.IsExist(p) {\n    if st, err := os.Stat(p); err == nil && st.IsDir() {\n        return errors.New(\"migration record path is a directory, not a file\")\n    }\n}","typeGuard":null,"tryCatchPattern":"m, err := readMasterPasswordMigration()\nif err != nil {\n    if errors.Is(err, fs.ErrPermission) {\n        // prompt user to fix ownership/permissions of the migration file\n    }\n    return nil, err // never silently treat an unreadable record as absent\n}","preventionTips":["Run only one kernel instance per workspace to avoid file-lock contention","Exclude the data directory from tools that take exclusive file locks (sync/backup clients)","Keep consistent file ownership by always running the kernel as the same user","Treat an unreadable migration record as a hard error, never as 'no migration'"],"tags":["go","filesystem","file-read","migration","file-lock"],"backgroundTag":"file-read-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"}