siyuan-note/siyuan · error

read inline styles failed

Error message

read inline styles failed: %w

What it means

Before writing, the kernel reads the existing inline styles file under a file lock to compare content. Any read error other than os.IsNotExist (permission problems, I/O errors, lock corruption) aborts the update, wrapped as this error. A missing file is tolerated and treated as empty.

Solutions

  1. Check file permissions on the workspace storage directory and the styles file; fix with chown/chmod so the kernel user can read it.
  2. Verify the disk is writable and healthy (dmesg / disk utility); free space if the disk is full.
  3. Close other processes locking the file (other SiYuan instances, sync tools) and retry.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check readability before calling the API:
// if _, err := os.Stat(stylesPath); err == nil {
//     f, err := os.Open(stylesPath); if err != nil { fix permissions first } 
// }

Try / catch

if err != nil && strings.Contains(err.Error(), "read inline styles failed") {
    // check permissions/disk health, ensure no other process locks the file, then retry
}

Prevention

When it happens

Trigger: setInlineStylesData calling filelock.ReadFile on the styles path when the file exists but cannot be read: permission denied, disk I/O error, or the file being locked/corrupted at the OS level.

Common situations: Running the kernel as a different user than the file owner; read-only filesystem or full disk; the storage directory synced by another tool holding conflicting locks; SELinux/AppArmor restrictions.

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/f7773e9c4eb1010d. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/inline_style.go:288

				if _, used := indexes[index]; used {
					return nil, false, fmt.Errorf("attribute view custom color [%d] is still in use by attribute view [%s]",
						index, avID)
				}
			}
		}
	}
	data, err := gulu.JSON.MarshalIndentJSON(ret, "", "  ")
	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)

View on GitHub (pinned to 9f775e8a12)