{"record":{"id":"d009fbdd44a6afb0","repo":"gohugoio/hugo","slug":"unmarshal-failed-w","errorCode":null,"errorMessage":"unmarshal failed: %w","messagePattern":"unmarshal failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"parser/metadecoders/decoder.go","lineNumber":332,"sourceCode":"\t\tcase *any:\n\t\t\t*v = xmlValue\n\t\t}\n\tcase TOML:\n\t\terr = toml.Unmarshal(data, v)\n\tcase YAML:\n\t\treturn UnmarshalYaml(data, v)\n\tcase CSV:\n\t\treturn d.unmarshalCSV(data, v)\n\n\tdefault:\n\t\treturn fmt.Errorf(\"unmarshal of format %q is not supported\", f)\n\t}\n\n\tif err == nil {\n\t\treturn nil\n\t}\n\n\treturn toFileError(f, data, fmt.Errorf(\"unmarshal failed: %w\", err))\n}\n\nfunc (d Decoder) unmarshalCSV(data []byte, v any) error {\n\tr := csv.NewReader(bytes.NewReader(data))\n\tr.Comma = d.Delimiter\n\tr.Comment = d.Comment\n\tr.LazyQuotes = d.LazyQuotes\n\n\trecords, err := r.ReadAll()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tswitch vv := v.(type) {\n\tcase *any:\n\t\tswitch d.TargetType {\n\t\tcase \"map\":\n\t\t\tif len(records) < 2 {","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/parser/metadecoders/decoder.go#L314-L350","documentation":"Thrown by Decoder.UnmarshalTo (parser/metadecoders/decoder.go:332) as the catch-all wrapper when the underlying format-specific decoder (json.Unmarshal, toml.Unmarshal, ORG parser, or the XML path's residual error) returns a non-nil error that isn't already handled by an earlier specific branch. The %w preserves the original error and toFileError attaches file/content context.","triggerScenarios":"Malformed JSON (syntax error, trailing comma), malformed TOML, invalid ORG-mode syntax, or any decode-time error from the format library that isn't intercepted by the dedicated XML/CSV branches. Essentially any well-formedness violation in a data/front-matter file.","commonSituations":"A syntax error in a front-matter block (bad YAML indent caught by the YAML branch is separate, but JSON/TOML/ORG errors land here); a corrupt JSON data file under data/; a TOML config with a duplicate key or bad quoting; an ORG file with unsupported syntax.","solutions":["Read the wrapped error for the exact syntax issue and line/column if provided.","Validate the file with the appropriate linter (e.g. jq for JSON, a TOML validator) and fix the syntax.","Use Hugo's file-position hints in the error output to jump to the offending location.","If the error is in front matter, ensure correct delimiters (+++ vs ---) and format."],"exampleFix":"// before: data/bad.json\n{ \"k\": 1, }   // trailing comma\n\n// after\n{ \"k\": 1 }","handlingStrategy":"try-catch","validationCode":"// Lint JSON/TOML before loading.\nfunc isValidJSON(data []byte) bool {\n    return json.Valid(data)\n}","typeGuard":null,"tryCatchPattern":"if err := dec.UnmarshalTo(data, f, &m); err != nil {\n    return fmt.Errorf(\"malformed %s data: %w\", f, err)\n}","preventionTips":["Run jq/TOML validators on data files in CI.","Watch front-matter delimiters (+++ vs ---).","Use Hugo's position hints in errors to locate issues."],"tags":["metadecoders","json","toml","org","data","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}