gohugoio/hugo · error
failed to convert content for file %q: %s
Error message
failed to convert content for file %q: %s
What it means
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.
Source
Thrown at commands/import.go:332
os.MkdirAll(targetParentDir, 0o777)
contentBytes, err := os.ReadFile(path)
if err != nil {
c.r.logger.Errorln("Read file error:", path)
return err
}
pf, err := pageparser.ParseFrontMatterAndContent(bytes.NewReader(contentBytes))
if err != nil {
return fmt.Errorf("failed to parse file %q: %s", filename, err)
}
newmetadata, err := c.convertJekyllMetaData(pf.FrontMatter, postName, postDate, draft)
if err != nil {
return fmt.Errorf("failed to convert metadata for file %q: %s", filename, err)
}
content, err := c.convertJekyllContent(newmetadata, string(pf.Content))
if err != nil {
return fmt.Errorf("failed to convert content for file %q: %s", filename, err)
}
fs := hugofs.Os
if err := helpers.WriteToDisk(targetFile, strings.NewReader(content), fs); err != nil {
return fmt.Errorf("failed to save file %q: %s", filename, err)
}
return nil
}
func (c *importCommand) copyJekyllFilesAndFolders(jekyllRoot, dest string, jekyllPostDirs map[string]bool) (err error) {
fs := hugofs.Os
fi, err := fs.Stat(jekyllRoot)
if err != nil {
return err
}
if !fi.IsDir() {
return errors.New(jekyllRoot + " is not a directory")View on GitHub ↗ (pinned to 8a468df065)
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.
Example fix
<!-- before -->
{% highlight ruby %}
puts 'hi'
<!-- missing endhighlight -->
<!-- after -->
```ruby
puts 'hi'
``` Defensive patterns
Strategy: try-catch
Validate before calling
// Check the file is readable and has a front-matter delimiter
b, err := os.ReadFile(path)
if err != nil || !bytes.HasPrefix(b, []byte("---")) {
log.Printf("skip %s: no front matter", path)
} Try / catch
if err := importer.Convert(f); err != nil {
var pe *fs.PathError
if errors.As(err, &pe) {
// filesystem-level cause; report path and continue
}
log.Printf("content conversion failed for %s: %v", f.Name(), err)
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: Jekyll posts using plugin-specific or nested Liquid tags, unbalanced `{% highlight %}`/`{% endhighlight %}` blocks, or unusual template syntax accumulated over a long-lived blog.
Related errors
- failed to convert metadata for file %q: %s
- failed to save file %q: %s
- abort: jekyll root contains neither posts nor drafts
- filename not match
- language %q not found
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/a2697374f96b6c59.json.
Report an issue: GitHub ↗.