{"record":{"id":"45d135abf0b3eb20","repo":"gohugoio/hugo","slug":"failed-to-detect-format-from-content","errorCode":null,"errorMessage":"failed to detect format from content","messagePattern":"failed to detect format from content","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/transform/remarshal.go","lineNumber":44,"sourceCode":"\t\treturn \"\", err\n\t}\n\n\tif m, ok := data.(map[string]any); ok {\n\t\tmeta = m\n\t} else {\n\t\tfrom, err := cast.ToStringE(data)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\tfrom = strings.TrimSpace(from)\n\t\tif from == \"\" {\n\t\t\treturn \"\", nil\n\t\t}\n\n\t\tfromFormat := metadecoders.Default.FormatFromContentString(from)\n\t\tif fromFormat == \"\" {\n\t\t\treturn \"\", errors.New(\"failed to detect format from content\")\n\t\t}\n\n\t\tmeta, err = metadecoders.Default.UnmarshalToMap([]byte(from), fromFormat)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\t// Make it so 1.0 float64 prints as 1 etc.\n\tapplyMarshalTypes(meta)\n\n\tvar result bytes.Buffer\n\tif err := parser.InterfaceToConfig(meta, mark, &result); err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn result.String(), nil\n}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/transform/remarshal.go#L26-L62","documentation":"Thrown by transform.Remarshal when the input data string's format cannot be auto-detected by metadecoders (tpl/transform/remarshal.go:42-44). Remarshal converts between JSON/YAML/TOML; if the source content matches none of these the detector returns empty and the error is raised.","triggerScenarios":"Calling {{ transform.Remarshal \"yaml\" .SomeString }} where .SomeString is malformed or is plain text, CSV, INI, or otherwise not JSON/YAML/TOML.","commonSituations":"Passing truncated or commented-out front matter; feeding markdown body instead of front matter; encoding the data with an unsupported dialect; whitespace-only or non-ASCII delimiter issues.","solutions":["Ensure the input is valid JSON, YAML, or TOML (test by parsing it standalone first).","Pass a map instead of a string so detection is skipped: {{ transform.Remarshal \"yaml\" (dict \"a\" 1) }}.","Trim/clean the string before passing; remove stray characters."],"exampleFix":"// before\n{{ transform.Remarshal \"yaml\" .RawBody }}\n// after\n{{ transform.Remarshal \"yaml\" .Params.config }}","handlingStrategy":"validation","validationCode":"{{/* Validate input parses as JSON/YAML/TOML before Remarshal, or pass a dict */}}\n{{ transform.Remarshal \"yaml\" (dict \"a\" 1) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Feed front matter / config blocks, not raw content bodies.","Pass a map to bypass format detection."],"tags":["template-function","transform","remarshal","serialization","parsing"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}