siyuan-note/siyuan · error

create inline styles directory failed

Error message

create inline styles directory failed: %w

What it means

The kernel stores inline styles under a workspace storage subdirectory. If that directory does not exist, it creates it with os.MkdirAll; failure (permissions, read-only filesystem, path conflicts) aborts the write, wrapped as this error.

Solutions

  1. Ensure the workspace data/storage parent directories exist, are directories, and are writable by the kernel process user.
  2. Remove or rename any regular file that occupies the target directory path.
  3. Move the workspace off read-only/network mounts or run with sufficient privileges.
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure the parent storage directory exists and is writable beforehand:
// info, err := os.Stat(filepath.Dir(dataPath))
// writable := err == nil && info.IsDir()

Try / catch

if err != nil && strings.Contains(err.Error(), "create inline styles directory failed") {
    // inspect the wrapped cause: fix permissions or remove a blocking file, then retry
}

Prevention

When it happens

Trigger: First palette/styles write in a workspace where the target directory cannot be created — parent directory not writable, path component is a file, or the filesystem is read-only.

Common situations: Workspace on a read-only mount or network share; a regular file existing where the directory should be; running the kernel with insufficient OS permissions; antivirus blocking directory creation.

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@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/9913ea25bffaf817. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/inline_style.go:296

	if err != nil {
		return nil, false, fmt.Errorf("marshal inline styles failed: %w", err)
	}
	if maxInlineStylesFileSize < len(data) {
		return nil, false, fmt.Errorf("inline styles file exceeds the %d byte limit", maxInlineStylesFileSize)
	}

	dataPath := inlineStylesPath()
	oldData, readErr := filelock.ReadFile(dataPath)
	if readErr != nil && !os.IsNotExist(readErr) {
		return nil, false, fmt.Errorf("read inline styles failed: %w", readErr)
	}
	if bytes.Equal(oldData, data) {
		cacheWorkspaceAVPalette(ret.AV)
		return ret, false, nil
	}

	if err = os.MkdirAll(filepath.Dir(dataPath), 0755); err != nil {
		return nil, false, fmt.Errorf("create inline styles directory failed: %w", err)
	}
	if err = filelock.WriteFile(dataPath, data); err != nil {
		return nil, false, fmt.Errorf("write inline styles failed: %w", err)
	}
	cacheWorkspaceAVPalette(ret.AV)
	IncSync()
	for _, avID := range sortedAttributeViewUsageIDs(customColorUsage) {
		indexes := customColorUsage[avID]
		if intersectsCustomColorIndexes(indexes, changedCustomColorIndexes) {
			pushReloadAttrView(avID)
		}
	}
	return ret, true, nil
}

func inlineStylesPath() string {
	return filepath.Join(util.DataDir, "storage", "inline-styles.json")
}

View on GitHub (pinned to 9f775e8a12)