siyuan-note/siyuan · error

mkdir master password migration dir failed: %w

Error message

mkdir master password migration dir failed: %w

What it means

writeMasterPasswordMigrationUnlocked could not create the directory holding the master password migration state file. The migration record (unlocked box material) cannot be persisted, so the migration step aborts with this wrapped OS error.

Source

Thrown at kernel/model/crypto.go:540

	NewWrappedDEK []byte `json:"newWrappedDEK"`
	NewWrapNonce  []byte `json:"newWrapNonce"`
	Metadata      []byte `json:"metadata"`
}

func masterPasswordMigrationPath() string {
	return filepath.Join(util.DataDir, ".siyuan", "master-password-migration.json")
}

func writeMasterPasswordMigration(m *masterPasswordMigration) error {
	masterPasswordMigrationMu.Lock()
	defer masterPasswordMigrationMu.Unlock()
	return writeMasterPasswordMigrationUnlocked(m)
}

func writeMasterPasswordMigrationUnlocked(m *masterPasswordMigration) error {
	p := masterPasswordMigrationPath()
	if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
		return fmt.Errorf("mkdir master password migration dir failed: %w", err)
	}
	data, err := gulu.JSON.MarshalIndentJSON(m, "", "  ")
	if err != nil {
		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

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Grant the kernel process write permission on the workspace data directory
  2. Remove any regular file occupying the migration directory path
  3. Free disk space or remount read-write
  4. Verify masterPasswordMigrationPath() points inside the active workspace

Example fix

// before: data dir not writable
ls -ld ~/SiYuan/data # root-owned
// after
sudo chown -R $USER ~/SiYuan/data
err := writeMasterPasswordMigration(m) // succeeds
Defensive patterns

Strategy: try-catch

Validate before calling

if err := os.MkdirAll(filepath.Dir(masterPasswordMigrationPath()), 0755); err != nil {
    return fmt.Errorf("migration dir not creatable: %w", err)
}

Try / catch

if err := writeMasterPasswordMigration(m); err != nil {
    if os.IsPermission(errors.Unwrap(err)) {
        // instruct user to fix workspace data directory ownership
    }
    return err
}

Prevention

When it happens

Trigger: writeMasterPasswordMigration or removeMasterPasswordMigrationBox calls writeMasterPasswordMigrationUnlocked; os.MkdirAll(filepath.Dir(masterPasswordMigrationPath()), 0755) fails due to permissions, read-only FS, or a non-directory in the path.

Common situations: Workspace data directory with wrong ownership, read-only mount, full disk, or a stray file occupying the migration directory path.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/c24a9171cd1a7cf9. Report an issue: GitHub.