{"record":{"id":"f375c33190848c46","repo":"siyuan-note/siyuan","slug":"read-attribute-view-custom-color-usage-s-failed","errorCode":null,"errorMessage":"read attribute view custom color usage [%s] failed: %w","messagePattern":"read attribute view custom color usage \\[(.+?)\\] failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":437,"sourceCode":"\t}\n\tfor _, entry := range entries {\n\t\tif !entry.IsDir() || !ast.IsNodeIDPattern(entry.Name()) {\n\t\t\tcontinue\n\t\t}\n\t\tif err = appendPaths(filepath.Join(util.DataDir, entry.Name(), \"storage\", \"av\")); err != nil {\n\t\t\tif strict {\n\t\t\t\treturn nil, fmt.Errorf(\"list notebook attribute views [%s] failed: %w\", entry.Name(), err)\n\t\t\t}\n\t\t\tlogging.LogWarnf(\"list notebook attribute views [%s] for custom color refresh failed: %s\",\n\t\t\t\tentry.Name(), err)\n\t\t}\n\t}\n\tsort.Strings(paths)\n\tfor _, path := range paths {\n\t\tavID, indexes, readErr := av.ReadAttributeViewCustomColorUsageByPath(path)\n\t\tif readErr != nil {\n\t\t\tif strict {\n\t\t\t\treturn nil, fmt.Errorf(\"read attribute view custom color usage [%s] failed: %w\", avID, readErr)\n\t\t\t}\n\t\t\tlogging.LogWarnf(\"read attribute view custom color usage [%s] for refresh failed: %s\", avID, readErr)\n\t\t\tcontinue\n\t\t}\n\t\tused := ret[avID]\n\t\tif used == nil {\n\t\t\tused = map[int]struct{}{}\n\t\t\tret[avID] = used\n\t\t}\n\t\tfor _, index := range indexes {\n\t\t\tused[index] = struct{}{}\n\t\t}\n\t}\n\treturn ret, nil\n}\n\nfunc isInlineStylesRepoPath(filePath string) bool {\n\treturn filePath == inlineStylesRepoPath","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L419-L455","documentation":"After collecting all attribute-view file paths across notebooks, workspaceAttributeViewCustomColorUsage reads each one via av.ReadAttributeViewCustomColorUsageByPath to gather custom color usage. If reading/parsing one file fails in strict mode, the operation aborts with this wrapped error; otherwise the file is skipped with a logged warning and processing continues with the remaining files.","triggerScenarios":"setInlineStylesData invokes the custom-color-usage scan in strict mode and one <data>/<notebook>/storage/av/*.av file is corrupted, not valid JSON/gob, locked, or larger/shorter than expected so ReadAttributeViewCustomColorUsageByPath returns an error.","commonSituations":"A .av file truncated by an interrupted sync or crash, manually edited attribute-view files, permission errors after workspace migration, or an .av file written by an older/newer format version that the parser rejects.","solutions":["Identify the failing .av file from the wrapped inner error and restore it from backup/history (SiYuan keeps file history)","Fix file permissions on the storage/av directory and its files","Reopen the affected attribute view in SiYuan so it is re-serialized, or delete the corrupt file if the view is disposable (it will be rebuilt on next save)","Retry the operation; in non-strict mode the corrupt file is skipped automatically"],"exampleFix":"// before: strict abort on one corrupt .av file\navID, indexes, readErr := av.ReadAttributeViewCustomColorUsageByPath(path)\nif readErr != nil {\n    return nil, fmt.Errorf(\"read attribute view custom color usage [%s] failed: %w\", avID, readErr)\n}\n// after: tolerate single-file failures and keep scanning\nif readErr != nil {\n    logging.LogWarnf(\"skip unreadable av [%s]: %s\", path, readErr)\n    continue\n}","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nfunction avFileLooksValid(path) {\n  try { return fs.statSync(path).isFile() && fs.readFileSync(path).length > 0; }\n  catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.refreshCustomColorUsage();\n} catch (e) {\n  if (String(e).includes('read attribute view custom color usage')) {\n    // restore the named .av from file history, then retry\n  } else throw e;\n}","preventionTips":["Let SiYuan close cleanly (avoid killing the process mid-write of .av files)","Restore corrupt .av files from file history instead of hand-editing them","Keep backups of the data directory before bulk operations"],"tags":["attribute-view","file-read","corrupt-data"],"backgroundTag":"file-read-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}