{"record":{"id":"d6fdc7f9fe72034d","repo":"siyuan-note/siyuan","slug":"attribute-view-custom-color-must-not-be-null","errorCode":null,"errorMessage":"attribute view custom color must not be null","messagePattern":"attribute view custom color must not be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/color.go","lineNumber":129,"sourceCode":"\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tindexes[normalized.Index] = struct{}{}\n\t\tret = append(ret, normalized)\n\t}\n\n\tsort.Slice(ret, func(i, j int) bool {\n\t\treturn ret[i].Index < ret[j].Index\n\t})\n\tif nil == ret {\n\t\tret = []*AttributeViewCustomColor{}\n\t}\n\treturn\n}\n\nfunc normalizeAttributeViewCustomColor(color *AttributeViewCustomColor) (ret *AttributeViewCustomColor, err error) {\n\tif nil == color {\n\t\treturn nil, errors.New(\"attribute view custom color must not be null\")\n\t}\n\tif color.Index < CustomColorMinIndex || CustomColorMaxIndex < color.Index {\n\t\treturn nil, fmt.Errorf(\"attribute view custom color index [%d] is out of range [%d, %d]\",\n\t\t\tcolor.Index, CustomColorMinIndex, CustomColorMaxIndex)\n\t}\n\n\tret = &AttributeViewCustomColor{Index: color.Index, Hidden: color.Hidden}\n\tret.Light, err = normalizeAttributeViewColorTheme(color.Light)\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"invalid light theme of attribute view custom color [%d]: %w\", color.Index, err)\n\t}\n\tret.Dark, err = normalizeAttributeViewColorTheme(color.Dark)\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"invalid dark theme of attribute view custom color [%d]: %w\", color.Index, err)\n\t}\n\treturn\n}\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/av/color.go#L111-L147","documentation":"normalizeAttributeViewCustomColor rejects a nil color entry with this sentinel message. A null element inside the custom colors array carries no index or theme data and cannot be normalized, so it is treated as invalid input.","triggerScenarios":"Passing a slice containing nil to av.NormalizeAttributeViewCustomColors (each element goes through normalizeAttributeViewCustomColor, color.go:129); JSON decoding that left null holes in the colors array (e.g. `[null, {...}]` or oversized arrays zero-filled).","commonSituations":"JSON like \"customColors\":[null,...] produced by another tool or a buggy writer; Go code building the slice with a nil entry from a failed lookup; a migration importing palettes where missing entries became null instead of being skipped.","solutions":["Filter out nil entries before calling NormalizeAttributeViewCustomColors.","Fix the JSON producer so absent colors are omitted from the array instead of written as null.","If the null came from decoding into a fixed-size array, switch to a variadic slice or pre-size the slice correctly.","In non-strict mode the entry still errors at normalizeAttributeViewCustomColor — filtering nils is required in both modes."],"exampleFix":"// before\nret, err := av.NormalizeAttributeViewCustomColors(colors, true) // colors contains nil\n\n// after\nfiltered := make([]*av.AttributeViewCustomColor, 0, len(colors))\nfor _, c := range colors {\n\tif c != nil {\n\t\tfiltered = append(filtered, c)\n\t}\n}\nret, err := av.NormalizeAttributeViewCustomColors(filtered, true)","handlingStrategy":"type-guard","validationCode":"func nonNil(colors []*av.AttributeViewCustomColor) []*av.AttributeViewCustomColor {\n\tout := colors[:0]\n\tfor _, c := range colors { if c != nil { out = append(out, c) } }\n\treturn out\n}","typeGuard":"func isValidColor(c *av.AttributeViewCustomColor) bool { return c != nil }","tryCatchPattern":"if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil && strings.Contains(err.Error(), \"must not be null\") {\n\t// filter nils and retry\n}","preventionTips":["Filter nil entries from color slices before normalizing","Never serialize null elements into the customColors JSON array","Check JSON decoding results for zero-fill holes in fixed-size arrays"],"tags":["attribute-view","custom-color","null-argument","validation","siyuan-kernel"],"backgroundTag":"null-argument","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"}