{"record":{"id":"3dfd87e8dac1bd4b","repo":"gohugoio/hugo","slug":"unmarshal-takes-1-or-2-arguments","errorCode":null,"errorMessage":"unmarshal takes 1 or 2 arguments","messagePattern":"unmarshal takes 1 or 2 arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/transform/unmarshal.go","lineNumber":40,"sourceCode":"\t\"github.com/gohugoio/hugo/resources\"\n\t\"github.com/gohugoio/hugo/resources/resource\"\n\n\t\"github.com/gohugoio/hugo/common/hashing\"\n\t\"github.com/gohugoio/hugo/common/types\"\n\n\t\"github.com/mitchellh/mapstructure\"\n\n\t\"github.com/gohugoio/hugo/parser/metadecoders\"\n\n\t\"github.com/spf13/cast\"\n)\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 {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/transform/unmarshal.go#L22-L58","documentation":"Thrown by transform.Unmarshal when the argument count is not 1 or 2 (tpl/transform/unmarshal.go:39-40). Unmarshal accepts either data alone, or an options map plus data; zero args or three-plus are rejected.","triggerScenarios":"Calling {{ transform.Unmarshal }} with no args, or {{ transform.Unmarshal .Opts .Data .Extra }} with three.","commonSituations":"Forgetting to pass the data; piping nothing; refactoring and leaving extra args; assuming options can be split across multiple positional args.","solutions":["Provide exactly one (data) or two (options map, data) arguments.","Combine options into a single map: {{ transform.Unmarshal (dict \"delimiter\" \",\") .CSV }}.","Ensure a value is piped or passed: {{ \"...\" | transform.Unmarshal }}."],"exampleFix":"// before\n{{ transform.Unmarshal .Opts .Data .Extra }}\n// after\n{{ transform.Unmarshal (dict \"delimiter\" \",\") .CSV }}","handlingStrategy":"validation","validationCode":"{{ transform.Unmarshal (dict \"delimiter\" \",\") .CSV }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unmarshal takes 1 (data) or 2 (options map + data) args.","Combine options into a single dict."],"tags":["template-function","transform","unmarshal","arity","argument"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}