{"record":{"id":"257165c3e35f7a53","repo":"gohugoio/hugo","slug":"failed-to-save-file-q-w","errorCode":null,"errorMessage":"failed to save file %q:: %w","messagePattern":"failed to save file %q:: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/convert.go","lineNumber":199,"sourceCode":"\tif err != nil {\n\t\tsite.Log.Errorln(errMsg)\n\t\treturn err\n\t}\n\n\tnewContent.Write(pf.Content)\n\n\tnewFilename := p.File().Filename()\n\n\tif c.outputDir != \"\" {\n\t\tcontentDir := strings.TrimSuffix(newFilename, p.File().Path())\n\t\tcontentDir = filepath.Base(contentDir)\n\n\t\tnewFilename = filepath.Join(c.outputDir, contentDir, p.File().Path())\n\t}\n\n\tfs := hugofs.Os\n\tif err := helpers.WriteToDisk(newFilename, &newContent, fs); err != nil {\n\t\treturn fmt.Errorf(\"failed to save file %q:: %w\", newFilename, err)\n\t}\n\n\treturn nil\n}\n\nfunc (c *convertCommand) copyContentDirsForOutput(pagesBackedByFile page.Pages) error {\n\tcontentDirs := make(map[string]bool)\n\tfor _, p := range pagesBackedByFile {\n\t\tfilename := p.File().Filename()\n\t\tcontentDir := strings.TrimSuffix(filename, p.File().Path())\n\t\tif contentDir == filename {\n\t\t\tcontinue\n\t\t}\n\t\tcontentDirs[filepath.Clean(contentDir)] = true\n\t}\n\n\tvar contentDirList []string\n\tfor contentDir := range contentDirs {","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/convert.go#L181-L217","documentation":"After converting front matter, convertAndSavePage writes the result with helpers.WriteToDisk (convert.go:198-199). If the write fails the error is wrapped with the target filename. Note the message contains a doubled colon ('::') typo.","triggerScenarios":"The output directory does not exist or is not writable, the disk is full, the path is too long, or a parent directory is missing.","commonSituations":"Using --output with a directory that lacks write permission; output on a read-only filesystem; disk full; path exceeds OS limits.","solutions":["Ensure the output directory exists and is writable (mkdir -p and chmod)","Provide a valid writable --output path","Check available disk space","Run with appropriate user permissions for the output location"],"exampleFix":"# before\nhugo convert toYAML --output /opt/readonly/out\n# after\nmkdir -p ~/converted && hugo convert toYAML --output ~/converted","handlingStrategy":"validation","validationCode":"// Verify the output directory is writable before running hugo convert.\nfunc ensureOutputWritable(dir string) error {\n    if err := os.MkdirAll(dir, 0o755); err != nil {\n        return err\n    }\n    probe := filepath.Join(dir, \".write_test\")\n    return os.WriteFile(probe, []byte(\"x\"), 0o644)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create and chmod the --output directory before running hugo convert","Check disk space before large conversions","Use a fresh output directory to avoid permission conflicts"],"tags":["convert","filesystem","write","cli","permissions","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}