{"record":{"id":"ca1c60de617e7aee","repo":"gohugoio/hugo","slug":"cannot-unmarshal-csv-into-t-invalid-targettype","errorCode":null,"errorMessage":"cannot unmarshal CSV into %T: invalid targetType: expected either slice or map, received %s","messagePattern":"cannot unmarshal CSV into %T: invalid targetType: expected either slice or map, received (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"parser/metadecoders/decoder.go","lineNumber":374,"sourceCode":"\t\t\t\tif seen[fieldName] {\n\t\t\t\t\treturn fmt.Errorf(\"cannot unmarshal CSV into %T: header row contains duplicate field names\", v)\n\t\t\t\t}\n\t\t\t\tseen[fieldName] = true\n\t\t\t}\n\n\t\t\tsm := make([]map[string]string, len(records)-1)\n\t\t\tfor i, record := range records[1:] {\n\t\t\t\tm := make(map[string]string, len(records[0]))\n\t\t\t\tfor j, col := range record {\n\t\t\t\t\tm[records[0][j]] = col\n\t\t\t\t}\n\t\t\t\tsm[i] = m\n\t\t\t}\n\t\t\t*vv = sm\n\t\tcase \"slice\":\n\t\t\t*vv = records\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"cannot unmarshal CSV into %T: invalid targetType: expected either slice or map, received %s\", v, d.TargetType)\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"cannot unmarshal CSV into %T\", v)\n\t}\n\n\treturn nil\n}\n\nfunc parseORGDate(s string) string {\n\tr := regexp.MustCompile(`[<\\[](\\d{4}-\\d{2}-\\d{2}) .*[>\\]]`)\n\tif m := r.FindStringSubmatch(s); m != nil {\n\t\treturn m[1]\n\t}\n\treturn s\n}\n\nfunc (d Decoder) unmarshalORG(data []byte, v any) error {\n\tconfig := org.New()","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/parser/metadecoders/decoder.go#L356-L392","documentation":"Thrown by Decoder.unmarshalCSV (parser/metadecoders/decoder.go:374) when decoding non-empty CSV into a *any target but Decoder.TargetType is neither \"map\" nor \"slice\". This mirrors the empty-data check (error 509) but fires for the populated-CSV path. The %s names the invalid TargetType.","triggerScenarios":"Constructing a Decoder with a misspelled/unsupported TargetType (e.g. \"object\", \"\", \"dict\") and decoding CSV data into *interface{}; using a custom Decoder instead of Default without setting TargetType correctly.","commonSituations":"Programmatic creation of a CSV decoder with a bad TargetType; relying on zero-value TargetType (\"\") instead of Default; a config field that feeds TargetType with an unexpected value.","solutions":["Set Decoder.TargetType to exactly \"slice\" or \"map\" for CSV decoding.","Use metadecoders.Default (TargetType=\"slice\") unless map mode is required.","Validate TargetType against {\"slice\",\"map\"} before invoking the decoder."],"exampleFix":"// before\ndec := metadecoders.Decoder{Delimiter: ',', TargetType: \"rows\"}\n\n// after\ndec := metadecoders.Default   // or TargetType: \"slice\"","handlingStrategy":"validation","validationCode":"func validCSVTargetType(t string) bool {\n    return t == \"map\" || t == \"slice\"\n}","typeGuard":null,"tryCatchPattern":"if err := dec.UnmarshalTo(data, metadecoders.CSV, &v); err != nil {\n    return fmt.Errorf(\"invalid CSV TargetType: %w\", err)\n}","preventionTips":["Use metadecoders.Default or set TargetType to map/slice for CSV.","Validate TargetType before building a custom Decoder."],"tags":["csv","metadecoders","config","api-misuse","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}