{"record":{"id":"d4c2dc95e1b61057","repo":"gohugoio/hugo","slug":"failed-to-copy-module-file-to-vendor-w","errorCode":null,"errorMessage":"failed to copy module file to vendor: %w","messagePattern":"failed to copy module file to vendor: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":256,"sourceCode":"\t\t\ttargetFilename := filepath.Join(vendorDir, t.PathVersionQuery(true), mount.Source)\n\t\t\tfi, err := c.fs.Stat(sourceFilename)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to vendor module: %w\", err)\n\t\t\t}\n\n\t\t\tif fi.IsDir() {\n\t\t\t\tif err := hugio.CopyDir(c.fs, sourceFilename, targetFilename, nil); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to copy module to vendor dir: %w\", err)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttargetDir := filepath.Dir(targetFilename)\n\n\t\t\t\tif err := c.fs.MkdirAll(targetDir, 0o755); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to make target dir: %w\", err)\n\t\t\t\t}\n\n\t\t\t\tif err := hugio.CopyFile(c.fs, sourceFilename, targetFilename); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to copy module file to vendor: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Include the resource cache if present.\n\t\tresourcesDir := filepath.Join(dir, files.FolderResources)\n\t\t_, err := c.fs.Stat(resourcesDir)\n\t\tif err == nil {\n\t\t\tif err := hugio.CopyDir(c.fs, resourcesDir, filepath.Join(vendorDir, t.PathVersionQuery(true), files.FolderResources), nil); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to copy resources to vendor dir: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\t// Include the config directory if present.\n\t\tconfigDir := filepath.Join(dir, \"config\")\n\t\t_, err = c.fs.Stat(configDir)\n\t\tif err == nil {\n\t\t\tif err := hugio.CopyDir(c.fs, configDir, filepath.Join(vendorDir, t.PathVersionQuery(true), \"config\"), nil); err != nil {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/modules/client.go#L238-L274","documentation":"Returned by Client.Vendor when hugio.CopyFile fails copying a single-file mount's source to the vendor target (after the target dir was successfully created). Wrapped with %w. Indicates the source file became inaccessible between Stat and CopyFile, or the target write was rejected.","triggerScenarios":"Running `hugo mod vendor` for a file-type mount where CopyFile returns an error: source removed/unreadable mid-copy, target path not writable, or afero write rejection. The earlier Stat (452 path) succeeded, so this is a transient or write-side failure.","commonSituations":"Concurrent process modifying the module cache (e.g. `go mod download` racing with vendor); a file with no read permission even though the dir Stat passed; target disk full; antivirus/SELinux blocking the write.","solutions":["Inspect the wrapped error to distinguish read failure (source) from write failure (target).","Re-run `hugo mod vendor` after stopping concurrent module downloads.","Fix source read permissions or the target write permissions.","Clear the module cache and re-download: `hugo mod clean` then vendor again."],"exampleFix":"# before: cache file unreadable\nhugo mod vendor   # CopyFile fails\n\n# after\nhugo mod clean\nhugo mod vendor","handlingStrategy":"try-catch","validationCode":"// Verify read access on source files and write access on target.\nfunc copyable(fs afero.Fs, src, dst string) error {\n    f, err := fs.Open(src)\n    if err != nil {\n        return err\n    }\n    f.Close()\n    return fs.MkdirAll(filepath.Dir(dst), 0o755)\n}","typeGuard":null,"tryCatchPattern":"if err := client.Vendor(); err != nil {\n    if strings.Contains(err.Error(), \"failed to copy module file to vendor\") {\n        // re-download module and retry; race or transient read failure\n    }\n}","preventionTips":["Do not run `go mod download` concurrently with `hugo mod vendor`.","Keep module cache readable; run `hugo mod clean` if files look corrupted."],"tags":["modules","vendoring","filesystem","copy","permissions"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}