gohugoio/hugo · error
unmarshal takes 1 or 2 arguments
Error message
unmarshal takes 1 or 2 arguments
What it means
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.
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 }}.
Example fix
// before
{{ transform.Unmarshal .Opts .Data .Extra }}
// after
{{ transform.Unmarshal (dict "delimiter" ",") .CSV }} Defensive patterns
Strategy: validation
Validate before calling
{{ transform.Unmarshal (dict "delimiter" ",") .CSV }} Prevention
- Unmarshal takes 1 (data) or 2 (options map + data) args.
- Combine options into a single dict.
When it happens
Trigger: Calling {{ transform.Unmarshal }} with no args, or {{ transform.Unmarshal .Opts .Data .Extra }} with three.
Common situations: Forgetting to pass the data; piping nothing; refactoring and leaving extra args; assuming options can be split across multiple positional args.
Related errors
- first argument must be a map
- must provide at least one argument
- transform.Highlight: expects at most 3 arguments
- failed to detect target data serialization format
- invalid arguments supplied to `time`
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/3dfd87e8dac1bd4b.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/transform/unmarshal.go:40
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
"github.com/gohugoio/hugo/common/hashing"
"github.com/gohugoio/hugo/common/types"
"github.com/mitchellh/mapstructure"
"github.com/gohugoio/hugo/parser/metadecoders"
"github.com/spf13/cast"
)
// Unmarshal unmarshals the data given, which can be either a string, json.RawMessage
// or a Resource. Supported formats are JSON, TOML, YAML, and CSV.
// You can optionally provide an options map as the first argument.
func (ns *Namespace) Unmarshal(args ...any) (any, error) {
if len(args) < 1 || len(args) > 2 {
return nil, errors.New("unmarshal takes 1 or 2 arguments")
}
var data any
decoder := metadecoders.Default
if len(args) == 1 {
data = args[0]
} else {
m, ok := args[0].(map[string]any)
if !ok {
return nil, errors.New("first argument must be a map")
}
var err error
data = args[1]
decoder, err = decodeDecoder(m)
if err != nil {View on GitHub (pinned to 52c9bd7908)