{"record":{"id":"2a6aa05c2c793da2","repo":"siyuan-note/siyuan","slug":"invalid-inline-style-id-s","errorCode":null,"errorMessage":"invalid inline style ID [%s]","messagePattern":"invalid inline style ID \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":664,"sourceCode":"\t}\n\tret = make([]*InlineStyle, 0, len(styles))\n\tids := make(map[string]struct{}, len(styles))\n\tfor _, style := range styles {\n\t\tif style == nil {\n\t\t\treturn nil, errors.New(\"inline style must not be null\")\n\t\t}\n\n\t\tid := strings.TrimSpace(style.ID)\n\t\tif id == \"\" && generateIDs {\n\t\t\tfor {\n\t\t\t\tid = ast.NewNodeID()\n\t\t\t\tif _, exists := ids[id]; !exists {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif !ast.IsNodeIDPattern(id) {\n\t\t\treturn nil, fmt.Errorf(\"invalid inline style ID [%s]\", id)\n\t\t}\n\t\tif _, exists := ids[id]; exists {\n\t\t\treturn nil, fmt.Errorf(\"duplicate inline style ID [%s]\", id)\n\t\t}\n\t\tids[id] = struct{}{}\n\n\t\tname := strings.TrimSpace(style.Name)\n\t\tif name == \"\" {\n\t\t\treturn nil, errors.New(\"inline style name must not be empty\")\n\t\t}\n\t\tif maxInlineStyleNameRunes < utf8.RuneCountInString(name) {\n\t\t\treturn nil, fmt.Errorf(\"inline style name exceeds the %d character limit\", maxInlineStyleNameRunes)\n\t\t}\n\t\tif style.Light == nil || style.Dark == nil {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must define light and dark themes\", id)\n\t\t}\n\n\t\tlight, err := normalizeInlineStyleTheme(style.Light)","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L646-L682","documentation":"Each custom inline style must have an ID matching the SiYuan node-ID pattern (ast.IsNodeIDPattern, e.g. 14-digit timestamp-based IDs). After optional auto-generation (only when generateIDs is true and the ID is empty), a non-empty ID that does not match the pattern causes the entire save/load to be rejected. This guarantees style IDs can be referenced as valid node IDs in document spans.","triggerScenarios":"Calling model.SetInlineStyles / model.SetInlineStylesData with a style whose ID is an arbitrary string like \"style-1\", a UUID, or whitespace-only while generateIDs is false; loading an inline styles config whose styles[] entry has a malformed ID (truncated, hand-crafted, or from an older/other format); an empty ID when generateIDs is false.","commonSituations":"External tools or sync merges writing style IDs that were never minted by ast.NewNodeID; hand-editing the JSON config; copying a style entry and mangling the ID; calling the API with a client-generated short slug instead of a node ID.","solutions":["Assign each style an ID produced by ast.NewNodeID() (14-digit node-ID format) before saving, or leave the ID empty so generateIDs mints one","Trim surrounding whitespace from the ID; only whitespace is tolerated (TrimSpace) — other characters are not","If the error arises on load, correct the malformed ID in the inline styles JSON to a valid node-ID pattern value","Do not reuse block IDs from other systems; use the kernel's ID generator"],"exampleFix":"// before\nstyle := &InlineStyle{ID: \"my-style\", Name: \"Mark\"}\nSetInlineStyles([]*InlineStyle{style}) // -> invalid inline style ID [my-style]\n// after\nstyle := &InlineStyle{ID: ast.NewNodeID(), Name: \"Mark\"}\nSetInlineStyles([]*InlineStyle{style})","handlingStrategy":"validation","validationCode":"func hasValidStyleIDs(styles []*InlineStyle) bool {\n\tfor _, s := range styles {\n\t\tid := strings.TrimSpace(s.ID)\n\t\tif id == \"\" || !ast.IsNodeIDPattern(id) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","typeGuard":"func hasNodeID(s *InlineStyle) bool { return ast.IsNodeIDPattern(strings.TrimSpace(s.ID)) }","tryCatchPattern":"ret, _, err := model.SetInlineStyles(styles)\nif err != nil {\n\tvar msg string\n\tif _, scan := fmt.Sscanf(err.Error(), \"invalid inline style ID %s\", &msg); scan == nil {\n\t\t// regenerate offending ID via ast.NewNodeID() and retry\n\t}\n\treturn err\n}","preventionTips":["Only mint IDs with ast.NewNodeID()","Never hand-write or shorten node IDs","Leave the ID empty so the kernel generates one when generateIDs is true"],"tags":["go","validation","identifier","inline-styles"],"backgroundTag":"invalid-identifier-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}