{"id":"3928391510685779","repo":"gohugoio/hugo","slug":"failed-to-parse-file-q-s","errorCode":null,"errorMessage":"failed to parse file %q: %s","messagePattern":"failed to parse file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/import.go","lineNumber":323,"sourceCode":"\tif err != nil {\n\t\tc.r.Printf(\"Failed to parse filename '%s': %s. Skipping.\", filename, err)\n\t\treturn nil\n\t}\n\n\tlog.Println(filename, postDate, postName)\n\n\ttargetFile := filepath.Join(targetDir, relPath)\n\ttargetParentDir := filepath.Dir(targetFile)\n\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","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/import.go#L305-L341","documentation":"Returned by `hugo import jekyll` while converting an individual Jekyll post when `pageparser.ParseFrontMatterAndContent` cannot parse the post's front matter and body (commands/import.go:321-324). The file was read successfully and its `YYYY-MM-DD-title` filename parsed; the failure is in the content itself — Hugo's page parser can't split or decode the front matter block, which aborts the whole import (unlike a bad filename, which is merely skipped).","triggerScenarios":"Importing a Jekyll site containing a `_posts` file with malformed front matter: unclosed `---` delimiters, invalid YAML inside the block (tabs for indentation, unquoted `:` in titles, duplicate keys), Liquid tags inside front matter values, or non-UTF-8 encoding that corrupts the delimiters.","commonSituations":"Old Jekyll posts with sloppy YAML that Jekyll's permissive parser tolerated but Hugo's stricter one rejects; posts with titles containing unescaped colons; merge-conflict markers left in front matter; CRLF/BOM issues from Windows-authored posts.","solutions":["The error names the file — open that _posts file and check the front matter block: matching `---` delimiters and valid YAML between them.","Quote scalar values containing colons or special characters (title: \"Foo: Bar\") and replace tabs with spaces.","Validate the front matter with yamllint or a YAML playground to find the exact syntax error.","Fix and re-run the import (with --force if the target is now non-empty)."],"exampleFix":"# before (_posts/2015-03-01-hello.md)\n---\ntitle: Hello: World\n---\n# after\n---\ntitle: \"Hello: World\"\n---","handlingStrategy":"try-catch","validationCode":"// Pre-lint source files for parseable front matter before importing\ndata, err := os.ReadFile(path)\nif err != nil {\n    return err\n}\nif !bytes.HasPrefix(data, []byte(\"---\")) && !bytes.HasPrefix(data, []byte(\"+++\")) {\n    // flag file: missing/odd front matter delimiter likely to fail parsing\n}","typeGuard":null,"tryCatchPattern":"if err := importFile(path); err != nil {\n    failures = append(failures, fmt.Sprintf(\"%s: %v\", path, err))\n    continue // keep importing the rest, report failures at the end\n}","preventionTips":["Validate front matter (YAML/TOML delimiters, encoding) in the source site before importing","Fix or exclude known-malformed files rather than letting one abort the batch","Run the import on a copy of the source so you can iterate on problem files safely"],"tags":["hugo","import","jekyll","front-matter","yaml","parsing"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}