{"record":{"id":"7509b40e56d5dd48","repo":"siyuan-note/siyuan","slug":"inline-style-name-must-not-be-empty","errorCode":null,"errorMessage":"inline style name must not be empty","messagePattern":"inline style name must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":673,"sourceCode":"\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)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid light theme of inline style [%s]: %w\", id, err)\n\t\t}\n\t\tdark, err := normalizeInlineStyleTheme(style.Dark)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid dark theme of inline style [%s]: %w\", id, err)\n\t\t}\n\t\tlightColor, lightBackground := light.Color != \"\", light.BackgroundColor != \"\"\n\t\tdarkColor, darkBackground := dark.Color != \"\", dark.BackgroundColor != \"\"","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L655-L691","documentation":"Every custom inline style requires a non-empty, non-whitespace Name; it is the label shown in the style picker UI. normalizeInlineStyles trims the name and rejects the entire save/load when the result is empty, because a nameless style cannot be identified by users.","triggerScenarios":"Calling model.SetInlineStyles / model.SetInlineStylesData with a style whose Name is \"\" or only whitespace; JSON config where the name field was deleted, left as \"\", or contains only spaces; UI code creating a style before the user typed a name; programmatic style creation that sets only ID/themes.","commonSituations":"An automation script building styles from a spreadsheet with a blank name cell; a frontend race saving the style dialog before name input completes; sync/merge dropping the name field; hand-edited JSON missing the key.","solutions":["Set a meaningful trimmed Name on every style before saving","In UI code, validate the name input is non-empty before invoking the API","Repair the config JSON by filling in the missing name if the error occurs on load","Default the name from a template (e.g. the color value) when none is provided"],"exampleFix":"// before\nSetInlineStyles([]*InlineStyle{{ID: id, Name: \"\", Light: l, Dark: d}})\n// -> \"inline style name must not be empty\"\n// after\nSetInlineStyles([]*InlineStyle{{ID: id, Name: \"Highlight\", Light: l, Dark: d}})","handlingStrategy":"validation","validationCode":"func allStylesNamed(styles []*InlineStyle) bool {\n\tfor _, s := range styles {\n\t\tif strings.TrimSpace(s.Name) == \"\" {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","typeGuard":"func hasName(s *InlineStyle) bool { return strings.TrimSpace(s.Name) != \"\" }","tryCatchPattern":"if _, _, err := model.SetInlineStyles(styles); err != nil {\n\tif strings.Contains(err.Error(), \"name must not be empty\") {\n\t\t// reject the input in the UI before resubmitting\n\t}\n\treturn err\n}","preventionTips":["Validate the name input in the UI before saving","Trim names and reject whitespace-only values early","Never create styles programmatically without a display name"],"tags":["go","validation","required-field","inline-styles"],"backgroundTag":"empty-required-field","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"}