{"id":"36aa43ffc4150ecb","repo":"gohugoio/hugo","slug":"symdiff-failed-to-convert-value-w","errorCode":null,"errorMessage":"symdiff: failed to convert value: %w","messagePattern":"symdiff: failed to convert value: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/symdiff.go","lineNumber":57,"sourceCode":"\t\tv := reflect.ValueOf(s)\n\n\t\tswitch v.Kind() {\n\t\tcase reflect.Array, reflect.Slice:\n\t\t\tif i == 0 {\n\t\t\t\tsliceType := v.Type()\n\t\t\t\tsliceElemType = sliceType.Elem()\n\t\t\t\tslice = reflect.MakeSlice(sliceType, 0, 0)\n\t\t\t}\n\n\t\t\tfor i := range v.Len() {\n\t\t\t\tev, _ := hreflect.Indirect(v.Index(i))\n\t\t\t\tkey := normalize(ev)\n\n\t\t\t\t// Append if the key is not in their intersection.\n\t\t\t\tif ids1[key] != ids2[key] {\n\t\t\t\t\tv, err := convertValue(ev, sliceElemType)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, fmt.Errorf(\"symdiff: failed to convert value: %w\", err)\n\t\t\t\t\t}\n\t\t\t\t\tslice = reflect.Append(slice, v)\n\t\t\t\t}\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"arguments to symdiff must be slices or arrays\")\n\t\t}\n\t}\n\n\treturn slice.Interface(), nil\n}\n","sourceCodeStart":39,"sourceCodeEnd":69,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/symdiff.go#L39-L69","documentation":"`collections.SymDiff` builds its result slice with the element type of the first slice argument, and converts each kept element to that type via `convertValue` (tpl/collections/symdiff.go:55-58). This error wraps a conversion failure: an element from the second collection cannot be represented as the first collection's element type, so a coherent result slice cannot be constructed.","triggerScenarios":"Calling `{{ $a | symdiff $b }}` where the two slices have incompatible element types — e.g. a `[]int` diffed against a slice of pages or structs, or mixed-type `[]any` slices whose leftover elements can't convert to the result's concrete element type.","commonSituations":"Diffing `.Pages` against a hand-built `slice` of strings or params; mixing values from `.Params` (which decode as varying concrete types) with typed collections; assuming symdiff works on heterogeneous data like union types.","solutions":["Make both collections the same element type before diffing — e.g. map both to strings or both to pages.","When comparing pages, diff the page collections directly (`.Pages | symdiff $other.Pages`) rather than mixing pages with scalars.","For mixed data, normalize with `apply` or a range that builds uniform slices, then symdiff those."],"exampleFix":"<!-- before: pages vs strings -->\n{{ $d := slice \"a\" \"b\" | symdiff .Pages }}\n<!-- after: compare like with like -->\n{{ $titles := slice }}{{ range .Pages }}{{ $titles = $titles | append .Title }}{{ end }}\n{{ $d := slice \"a\" \"b\" | symdiff $titles }}","handlingStrategy":"validation","validationCode":"{{/* ensure element types are comparable/convertible across the slices */}}\n{{ $a := slice 1 2 3 }}\n{{ $b := slice 2 3 4 }}\n{{ $diff := collections.SymDiff $a $b }}","typeGuard":null,"tryCatchPattern":"{{ with try (collections.SymDiff $a $b) }}\n  {{ with .Err }}{{ errorf \"symdiff: %s\" . }}{{ else }}{{ .Value }}{{ end }}\n{{ end }}","preventionTips":["Use slices of homogeneous, hashable scalar types (strings, numbers) — mixed or complex element types can fail conversion","Normalize elements (e.g. `string`-ify) before diffing when sources vary","Test symdiff with data from all content sources that feed it"],"tags":["hugo","templates","collections","type-conversion"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}