{"record":{"id":"3430df68f9e56671","repo":"gohugoio/hugo","slug":"unable-to-convert-value-of-type-q-to-q-3430df","errorCode":null,"errorMessage":"unable to convert value of type %q to %q","messagePattern":"unable to convert value of type %q to %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/reflect_helpers.go","lineNumber":100,"sourceCode":"func convertValue(v reflect.Value, to reflect.Type) (reflect.Value, error) {\n\tif v.Type().AssignableTo(to) {\n\t\treturn v, nil\n\t}\n\tswitch kind := to.Kind(); {\n\tcase kind == reflect.String:\n\t\treturn hreflect.ToStringValueE(v)\n\tcase hreflect.IsNumber(kind):\n\t\treturn convertNumber(v, to)\n\tdefault:\n\t\treturn reflect.Value{}, fmt.Errorf(\"%s is not assignable to %s\", v.Type(), to)\n\t}\n}\n\nfunc convertNumber(v reflect.Value, typ reflect.Type) (reflect.Value, error) {\n\tif v, ok := hreflect.ConvertIfPossible(v, typ); ok {\n\t\treturn v, nil\n\t}\n\treturn reflect.Value{}, fmt.Errorf(\"unable to convert value of type %q to %q\", v.Type().String(), typ.String())\n}\n\nfunc newSliceElement(items any) any {\n\ttp := reflect.TypeOf(items)\n\tif tp == nil {\n\t\treturn nil\n\t}\n\tswitch tp.Kind() {\n\tcase reflect.Array, reflect.Slice:\n\t\ttp = tp.Elem()\n\t\tif tp.Kind() == reflect.Pointer {\n\t\t\ttp = tp.Elem()\n\t\t}\n\n\t\treturn reflect.New(tp).Interface()\n\t}\n\treturn nil\n}","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/reflect_helpers.go#L82-L118","documentation":"Thrown by convertNumber when hreflect.ConvertIfPossible cannot convert a numeric value to the target numeric type. convertNumber is the numeric branch of convertValue, used by set operations to reconcile e.g. int vs int64 vs float64 element types. Both source and target type names are quoted in the message.","triggerScenarios":"SymDiff (or another caller) where slices have numeric element types that hreflect refuses to convert — e.g. a custom numeric type that isn't directly convertible, or an edge case in numeric kind handling. The ConvertIfPossible fast-path returns false, falling through to the error.","commonSituations":"Custom typed integers/floats in data structures, or version changes where hreflect's conversion support narrowed. Relatively rare since standard numeric kinds usually convert.","solutions":["Normalize element types to a standard kind (int, int64, float64) before the set operation.","Avoid custom numeric types in slices passed to SymDiff.","Map elements to plain int/float64 upstream.","Check hreflect.ConvertIfPossible support for your specific types."],"exampleFix":"// before\n{{ symdiff $customIntSlice $int64Slice }}\n// after\n{{ symdiff $intSliceA $intSliceB }}","handlingStrategy":"validation","validationCode":"func numericTypesConvertible(src, dst reflect.Type) bool {\n    if !hreflect.IsNumber(src.Kind()) || !hreflect.IsNumber(dst.Kind()) { return false }\n    _, ok := hreflect.ConvertIfPossible(reflect.Zero(src), dst)\n    return ok\n}","typeGuard":"func isStandardNumeric(t reflect.Type) bool {\n    switch t.Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n         reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n         reflect.Float32, reflect.Float64:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Normalize slice element types to standard int/int64/float64 before set operations.","Avoid custom numeric types in slices passed to SymDiff.","Map custom numerics to plain int/float64 upstream.","Verify hreflect.ConvertIfPossible supports your types."],"tags":["go","hugo","template","collections","numeric","conversion"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}