{"record":{"id":"ba4443a32b418857","repo":"gohugoio/hugo","slug":"failed-to-decode-options-w-ba4443","errorCode":null,"errorMessage":"failed to decode options: %w","messagePattern":"failed to decode options: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/transform/unmarshal.go","lineNumber":59,"sourceCode":"\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\n\t\tif decoder != metadecoders.Default {\n\t\t\tkey += decoder.OptionsKey()\n\t\t}\n\n\t\tv, err := ns.cacheUnmarshal.GetOrCreate(key, func(string) (*resources.StaleValue[any], error) {\n\t\t\tvar f metadecoders.Format\n\t\t\tif decoder.Format != \"\" {\n\t\t\t\tf = metadecoders.FormatFromString(decoder.Format)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/transform/unmarshal.go#L41-L77","documentation":"transform.Unmarshal accepts an optional first-argument options map (e.g. {{ transform.Unmarshal (dict \"delimiter\" \";\") $data }}). decodeDecoder (unmarshal.go:167-198) processes this map — handling Delimiter/Comment as runes and WeakDecode-ing the rest into metadecoders.Decoder options. If any of that fails, the error wraps the decode failure (unmarshal.go:57-60).","triggerScenarios":"Passing an options map to transform.Unmarshal with an invalid value — e.g. a multi-character string for Delimiter/Comment (stringToRune rejects >1 char at unmarshal.go:216), or a value WeakDecode cannot coerce into the Decoder struct.","commonSituations":"Setting Delimiter to \",,\" instead of \",\" for CSV; passing an unknown option type; typos in option keys that mapstructure then mishandles; copying CSV examples with wrong delimiter values.","solutions":["Ensure Delimiter and Comment are single-character strings.","Remove unsupported/unknown keys from the options map.","Check the wrapped error for the specific field that failed."],"exampleFix":"// before — multi-char delimiter rejected\n{{ transform.Unmarshal (dict \"delimiter\" \",,\") $csvResource }}\n\n// after — single-char delimiter\n{{ transform.Unmarshal (dict \"delimiter\" \",\") $csvResource }}","handlingStrategy":"validation","validationCode":"// Validate option keys/types before passing to transform.Unmarshal:\n//   - Delimiter and Comment must be single characters\n//   - Only known keys: delimiter, comment, format (and decoder-specific ones)\n{{ transform.Unmarshal (dict \"delimiter\" \",\") $csv }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep Delimiter/Comment to exactly one character.","Avoid unknown option keys.","Inspect the wrapped decode error for the offending field."],"tags":["transform","unmarshal","options","csv","decode","template"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}