{"id":"a2697374f96b6c59","repo":"gohugoio/hugo","slug":"failed-to-convert-content-for-file-q-s","errorCode":null,"errorMessage":"failed to convert content for file %q: %s","messagePattern":"failed to convert content for file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/import.go","lineNumber":332,"sourceCode":"\tos.MkdirAll(targetParentDir, 0o777)\n\n\tcontentBytes, err := os.ReadFile(path)\n\tif err != nil {\n\t\tc.r.logger.Errorln(\"Read file error:\", path)\n\t\treturn err\n\t}\n\tpf, err := pageparser.ParseFrontMatterAndContent(bytes.NewReader(contentBytes))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse file %q: %s\", filename, err)\n\t}\n\tnewmetadata, err := c.convertJekyllMetaData(pf.FrontMatter, postName, postDate, draft)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to convert metadata for file %q: %s\", filename, err)\n\t}\n\n\tcontent, err := c.convertJekyllContent(newmetadata, string(pf.Content))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to convert content for file %q: %s\", filename, err)\n\t}\n\n\tfs := hugofs.Os\n\tif err := helpers.WriteToDisk(targetFile, strings.NewReader(content), fs); err != nil {\n\t\treturn fmt.Errorf(\"failed to save file %q: %s\", filename, err)\n\t}\n\treturn nil\n}\n\nfunc (c *importCommand) copyJekyllFilesAndFolders(jekyllRoot, dest string, jekyllPostDirs map[string]bool) (err error) {\n\tfs := hugofs.Os\n\n\tfi, err := fs.Stat(jekyllRoot)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !fi.IsDir() {\n\t\treturn errors.New(jekyllRoot + \" is not a directory\")","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/import.go#L314-L350","documentation":"Emitted in `convertJekyllPost` when `convertJekyllContent` fails while rewriting a post's body from Jekyll conventions to Hugo. The converter translates Liquid constructs such as `{% highlight %}` / `{% raw %}` tags and rendering hints derived from the metadata; a failure there aborts conversion of that file.","triggerScenarios":"`hugo import jekyll` processing a post whose body contains Liquid tags or content the regex-based converters cannot transform, or metadata-driven templating of the new front matter failing for that content.","commonSituations":"Jekyll posts using plugin-specific or nested Liquid tags, unbalanced `{% highlight %}`/`{% endhighlight %}` blocks, or unusual template syntax accumulated over a long-lived blog.","solutions":["Check the wrapped error and open the named file to locate the problematic Liquid construct.","Simplify or remove unsupported/unbalanced Liquid tags (e.g. fix `{% highlight %}` blocks) and re-run the import.","Convert the problematic post manually: strip Liquid tags and use Hugo's `highlight` shortcode or fenced code blocks."],"exampleFix":"<!-- before -->\n{% highlight ruby %}\nputs 'hi'\n<!-- missing endhighlight -->\n<!-- after -->\n```ruby\nputs 'hi'\n```","handlingStrategy":"try-catch","validationCode":"// Check the file is readable and has a front-matter delimiter\nb, err := os.ReadFile(path)\nif err != nil || !bytes.HasPrefix(b, []byte(\"---\")) {\n    log.Printf(\"skip %s: no front matter\", path)\n}","typeGuard":null,"tryCatchPattern":"if err := importer.Convert(f); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) {\n        // filesystem-level cause; report path and continue\n    }\n    log.Printf(\"content conversion failed for %s: %v\", f.Name(), err)\n}","preventionTips":["Ensure posts are UTF-8 encoded before import","Remove Liquid tags Hugo cannot translate, or expect manual fixup","Iterate file-by-file and collect errors instead of aborting the whole batch"],"tags":["hugo","jekyll-import","liquid","content-conversion"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}