{"record":{"id":"bc89f999b3faece9","repo":"gohugoio/hugo","slug":"failed-to-save-file-q-s","errorCode":null,"errorMessage":"failed to save file %q: %s","messagePattern":"failed to save file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/import.go","lineNumber":337,"sourceCode":"\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\")\n\t}\n\terr = os.MkdirAll(dest, fi.Mode())\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/import.go#L319-L355","documentation":"After conversion, the importer writes the new Markdown to `targetFile` via `helpers.WriteToDisk`. This wraps a filesystem write failure for the converted post; `%q` is the source (Jekyll) filename, `%s` the underlying I/O error.","triggerScenarios":"Fires when `WriteToDisk` cannot create/write the target file — destination directory not creatable, out of disk space, permission denied, or a read-only filesystem.","commonSituations":"Importing into a `--target` directory on a read-only volume; running out of disk during a large import; a target path that conflicts with an existing file marked read-only; CI without write access to the output dir.","solutions":["Confirm the target directory exists and is writable (`-w` check).","Free disk space or move the target to a volume with capacity.","Re-run the import after correcting permissions on the destination.","Use an absolute `--target` path under a directory you own."],"exampleFix":"// before\n// $ hugo import jekyll ~/blog ~/hugo --target=/srv/readonly\n// after\n// $ hugo import jekyll ~/blog ~/hugo --target=/home/me/hugo-content","handlingStrategy":"validation","validationCode":"// Verify the target directory is writable before importing.\nfunc validateTargetDir(dir string) error {\n  fi, err := os.Stat(dir)\n  if err != nil { return err }\n  if !fi.IsDir() { return fmt.Errorf(\"%s is not a directory\", dir) }\n  f, err := os.CreateTemp(dir, \".hugoimp-*\")\n  if err != nil { return err }\n  f.Close(); os.Remove(f.Name())\n  return nil\n}","typeGuard":"null","tryCatchPattern":"// On write failure, retry once with a fresh path, then report.\nif err := helpers.WriteToDisk(targetFile, r, fs); err != nil {\n  if errors.Is(err, os.ErrPermission) { /* fix perms / pick new target */ }\n}","preventionTips":["Pass an absolute `--target` under a directory you own.","Confirm free disk space before large imports.","Run imports with write access to the destination volume."],"tags":["hugo","import","filesystem","io"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}