{"record":{"id":"a88bfba4732ce6c3","repo":"gohugoio/hugo","slug":"first-argument-must-be-a-map-a88bfb","errorCode":null,"errorMessage":"first argument must be a map","messagePattern":"first argument must be a map","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/transform/unmarshal.go","lineNumber":51,"sourceCode":")\n\n// Unmarshal unmarshals the data given, which can be either a string, json.RawMessage\n// or a Resource. Supported formats are JSON, TOML, YAML, and CSV.\n// You can optionally provide an options map as the first argument.\nfunc (ns *Namespace) Unmarshal(args ...any) (any, error) {\n\tif len(args) < 1 || len(args) > 2 {\n\t\treturn nil, errors.New(\"unmarshal takes 1 or 2 arguments\")\n\t}\n\n\tvar data any\n\tdecoder := metadecoders.Default\n\n\tif len(args) == 1 {\n\t\tdata = args[0]\n\t} else {\n\t\tm, ok := args[0].(map[string]any)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"first argument must be a map\")\n\t\t}\n\n\t\tvar err error\n\n\t\tdata = args[1]\n\t\tdecoder, err = decodeDecoder(m)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to decode options: %w\", err)\n\t\t}\n\t}\n\n\tif r, ok := data.(resource.UnmarshableResource); ok {\n\t\tkey := r.Key()\n\n\t\tif key == \"\" {\n\t\t\treturn nil, errors.New(\"no Key set in Resource\")\n\t\t}\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/transform/unmarshal.go#L33-L69","documentation":"Thrown by transform.Unmarshal when two arguments are supplied but the first is not a map[string]any (tpl/transform/unmarshal.go:49-51). In the two-argument form the first argument must be an options map (e.g. CSV delimiter/comment); the second is the data.","triggerScenarios":"Calling {{ transform.Unmarshal \"csv\" .Data }} (string instead of map) or {{ transform.Unmarshal .SomeString .Data }}.","commonSituations":"Passing the format as a plain string instead of an options map; misreading the signature; piping a string then data.","solutions":["Use a map (dict) for options: {{ transform.Unmarshal (dict \"delimiter\" \",\") .CSV }}.","If you have no options, pass only the data: {{ transform.Unmarshal .Data }}."],"exampleFix":"// before\n{{ transform.Unmarshal \"csv\" .CSVData }}\n// after\n{{ transform.Unmarshal (dict \"delimiter\" \",\") .CSVData }}","handlingStrategy":"type-guard","validationCode":"{{ transform.Unmarshal (dict \"delimiter\" \",\") .CSV }}","typeGuard":"{{/* first arg must be map[string]any when two args given */}}\n{{ if reflect.IsMap .Opts }}{{ transform.Unmarshal .Opts .Data }}{{ else }}{{ transform.Unmarshal .Data }}{{ end }}","tryCatchPattern":null,"preventionTips":["Use dict to build the options map.","Pass options as a map, not a format string."],"tags":["template-function","transform","unmarshal","type-coercion","argument"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}