siyuan-note/siyuan · error

read master password migration failed

Error message

read master password migration failed: %w

What it means

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.

Solutions

  1. Check and fix permissions/ownership of the migration file under the workspace data directory
  2. Stop other kernel instances or sync/backup tools that may hold the file lock, then retry
  3. 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
  4. Check disk health (dmesg/SMART) if I/O errors persist

Example fix

// diagnose
ls -l <workspace>/data/<migration-file>
fuser -v <workspace>/data/<migration-file>
// fix
sudo chown <user> <workspace>/data/<migration-file> && chmod u+rw <workspace>/data/<migration-file>
Defensive patterns

Strategy: try-catch

Validate before calling

p := masterPasswordMigrationPath()
if filelock.IsExist(p) {
    if st, err := os.Stat(p); err == nil && st.IsDir() {
        return errors.New("migration record path is a directory, not a file")
    }
}

Try / catch

m, err := readMasterPasswordMigration()
if err != nil {
    if errors.Is(err, fs.ErrPermission) {
        // prompt user to fix ownership/permissions of the migration file
    }
    return nil, err // never silently treat an unreadable record as absent
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


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

Appendix: source

Thrown at kernel/model/crypto.go:562

		return fmt.Errorf("marshal master password migration failed: %w", err)
	}
	return filelock.WriteFile(p, data)
}

func readMasterPasswordMigration() (*masterPasswordMigration, error) {
	masterPasswordMigrationMu.Lock()
	defer masterPasswordMigrationMu.Unlock()
	return readMasterPasswordMigrationUnlocked()
}

func readMasterPasswordMigrationUnlocked() (*masterPasswordMigration, error) {
	p := masterPasswordMigrationPath()
	if !filelock.IsExist(p) {
		return nil, nil
	}
	data, err := filelock.ReadFile(p)
	if err != nil {
		return nil, fmt.Errorf("read master password migration failed: %w", err)
	}
	var m masterPasswordMigration
	if err = gulu.JSON.UnmarshalJSON(data, &m); err != nil {
		return nil, fmt.Errorf("unmarshal master password migration failed: %w", err)
	}
	return &m, nil
}

func removeMasterPasswordMigration() {
	masterPasswordMigrationMu.Lock()
	defer masterPasswordMigrationMu.Unlock()
	removeMasterPasswordMigrationUnlocked()
}

func removeMasterPasswordMigrationUnlocked() {
	p := masterPasswordMigrationPath()
	if err := filelock.Remove(p); err != nil && !os.IsNotExist(err) {
		logging.LogErrorf("remove master password migration failed: %s", err)

View on GitHub (pinned to 9f775e8a12)