siyuan-note/siyuan · error

read attribute view custom color usage

Error message

read attribute view custom color usage [%s] failed: %w

What it means

While collecting which custom colors are used by each attribute view, av.ReadAttributeViewCustomColorUsageByPath failed for one .json attribute view file. The kernel wraps the AV ID and underlying error. In strict mode this aborts the whole custom color usage refresh; otherwise it is logged and the file is skipped.

Solutions

  1. Inspect the wrapped cause for the specific av file and validate its JSON structure
  2. Fix permissions on <workspace>/data/**/storage/av/*.json
  3. Restore the corrupt .json attribute view file from backup or sync history, then retry

Example fix

// before (strict abort)
return nil, fmt.Errorf("read attribute view custom color usage [%s] failed: %w", avID, readErr)
// after: call with strict=false so bad files are skipped
usage, err := workspaceAttributeViewCustomColorUsage(false)
Defensive patterns

Strategy: try-catch

Validate before calling

const raw = fs.readFileSync(avPath, 'utf8');
JSON.parse(raw); // throws before the API call if the av file is corrupt

Type guard

const isAvJson = (s) => { try { const o = JSON.parse(s); return typeof o === 'object' && o !== null; } catch { return false; } };

Try / catch

try {
  await fetchPost('/api/attr/setInlineStylesData', payload);
} catch (e) {
  if (String(e).includes('read attribute view custom color usage')) {
    logging.warn(`corrupt attribute view ignored: ${e}`);
  }
}

Prevention

When it happens

Trigger: setInlineStylesData iterating a corrupt, unreadable, or malformed .json file under data/storage/av or <notebook>/storage/av when strict=true.

Common situations: Partially written or corrupted attribute view JSON from an interrupted sync, permission-restricted av files, hand-edited JSON with invalid structure.

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

Appendix: source

Thrown at kernel/model/inline_style.go:437

	}
	for _, entry := range entries {
		if !entry.IsDir() || !ast.IsNodeIDPattern(entry.Name()) {
			continue
		}
		if err = appendPaths(filepath.Join(util.DataDir, entry.Name(), "storage", "av")); err != nil {
			if strict {
				return nil, fmt.Errorf("list notebook attribute views [%s] failed: %w", entry.Name(), err)
			}
			logging.LogWarnf("list notebook attribute views [%s] for custom color refresh failed: %s",
				entry.Name(), err)
		}
	}
	sort.Strings(paths)
	for _, path := range paths {
		avID, indexes, readErr := av.ReadAttributeViewCustomColorUsageByPath(path)
		if readErr != nil {
			if strict {
				return nil, fmt.Errorf("read attribute view custom color usage [%s] failed: %w", avID, readErr)
			}
			logging.LogWarnf("read attribute view custom color usage [%s] for refresh failed: %s", avID, readErr)
			continue
		}
		used := ret[avID]
		if used == nil {
			used = map[int]struct{}{}
			ret[avID] = used
		}
		for _, index := range indexes {
			used[index] = struct{}{}
		}
	}
	return ret, nil
}

func isInlineStylesRepoPath(filePath string) bool {
	return filePath == inlineStylesRepoPath

View on GitHub (pinned to 9f775e8a12)