siyuan-note/siyuan · error

Create notebook [ ] folder [ ] failed

Error message

Create notebook [%s] folder [%s] failed: %s

What it means

Box.Mkdir creates a single directory level inside a notebook after validateBoxPath. It uses os.Mkdir (not MkdirAll), so an existing directory (EEXIST) is an error like any other; the OS error is wrapped into localized message 6 'Create notebook [%s] folder [%s] failed: %s' and logged.

Solutions

  1. Check existence first (Box.Exist / stat) and skip or treat EEXIST as success for idempotent imports
  2. For nested paths, create each level or use the MkdirAll-backed path instead of one-shot Mkdir
  3. Sanitize folder names for the host filesystem and confirm the notebook is not read-only

Example fix

// before
box.Mkdir('imports/2026/notes'); // parent missing -> error

// after
box.MkdirAll('imports/2026/notes'); // creates every level
Defensive patterns

Strategy: validation

Validate before calling

if (!box.Exist(path)) { box.Mkdir(path) } // avoids EEXIST from single-level os.Mkdir

Prevention

When it happens

Trigger: POST /api/filetree/createDocWithMd or folder-creation paths calling Box.Mkdir for a path whose last segment already exists, contains an OS-illegal character, or sits under a read-only parent.

Common situations: Re-running an import script that recreates the same folder; concurrent requests racing to create the same path; folder names with characters the filesystem rejects.

Related errors


AI-assisted analysis of siyuan-note/siyuan@afa823b6b4 (2026-08-18). Data as JSON: /api/errors/4b555cbde9fc8628. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/box.go:433

	}
	return
}

func (box *Box) Exist(p string) bool {
	if _, err := box.validateBoxPath(p); err != nil {
		return false
	}
	return filelock.IsExist(filepath.Join(util.DataDir, box.ID, p))
}

func (box *Box) Mkdir(path string) error {
	if _, err := box.validateBoxPath(path); err != nil {
		return err
	}
	if err := os.Mkdir(filepath.Join(util.DataDir, box.ID, path), 0755); err != nil {
		msg := fmt.Sprintf(Conf.Language(6), box.Name, path, err)
		logging.LogErrorf("mkdir [path=%s] in box [%s] failed: %s", path, box.ID, err)
		return errors.New(msg)
	}
	IncSync()
	return nil
}

func (box *Box) MkdirAll(path string) error {
	if _, err := box.validateBoxPath(path); err != nil {
		return err
	}
	if err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, path), 0755); err != nil {
		msg := fmt.Sprintf(Conf.Language(6), box.Name, path, err)
		logging.LogErrorf("mkdir all [path=%s] in box [%s] failed: %s", path, box.ID, err)
		return errors.New(msg)
	}
	IncSync()
	return nil
}

View on GitHub (pinned to afa823b6b4)