{"record":{"id":"35302cf15f2b5a08","repo":"gohugoio/hugo","slug":"failed-to-copy-to-q-w","errorCode":null,"errorMessage":"failed to copy to %q: %w","messagePattern":"failed to copy to %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/batch.go","lineNumber":716,"sourceCode":"\t\t\t\ttargetFilenames = append(targetFilenames, targetFilename)\n\t\t\t}\n\n\t\t\tfs := b.client.d.BaseFs.PublishFs\n\n\t\t\tif err := func() error {\n\t\t\t\tfw, err := helpers.OpenFilesForWriting(fs, targetFilenames...)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tdefer fw.Close()\n\n\t\t\t\tfr := bytes.NewReader(o.Contents)\n\n\t\t\t\t_, err = io.Copy(fw, fr)\n\n\t\t\t\treturn err\n\t\t\t}(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to copy to %q: %w\", targetFilenames, err)\n\t\t\t}\n\t\t}\n\t}\n\n\tp := &Package{\n\t\tid:     path.Join(NsBatch, b.id),\n\t\tb:      b,\n\t\tgroups: groups,\n\t}\n\n\treturn p, nil\n}\n\nfunc (b *batcher) removeNotSet() bool {\n\t// We already have the lock.\n\tvar removed bool\n\tcurrentBuildID := b.buildCount\n\tfor k, v := range b.scriptGroups {","sourceCodeStart":698,"sourceCodeEnd":734,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/js/esbuild/batch.go#L698-L734","documentation":"Thrown when copying a non-resource output file (e.g. one emitted via the copy/file loader) to the publish directory fails. Either helpers.OpenFilesForWriting or io.Copy returned an error, and the printed targetFilenames show where the write failed.","triggerScenarios":"Esbuild emits an output file that isn't recognized as a resource (no media type or not in a path group), so Hugo copies it directly to each multihost-aware target. The copy fails because the publish directory is not writable, is out of space, or the joined target path is invalid.","commonSituations":"publishDir (often public/) is read-only or owned by another user; CI runs Hugo as a non-privileged user; out of disk; misconfigured multihost producing invalid joined paths; on Windows an anti-virus locks the destination file.","solutions":["Check write permissions on the publish directory (often public/).","Free disk space on the volume holding the publish dir.","Inspect the target path printed for invalid characters or traversal; verify each multihost base path is correct.","On Windows, exclude the Hugo publish dir from anti-virus scanning."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before the build, write and remove a sentinel file in the publish dir to\n// confirm the process has write access.\nsentinel := filepath.Join(publishDir, \".hugo-write-probe\")\nif err := os.WriteFile(sentinel, []byte(\"x\"), 0o644); err != nil {\n    return fmt.Errorf(\"publish dir not writable: %w\", err)\n}\n_ = os.Remove(sentinel)","typeGuard":null,"tryCatchPattern":"On copy failure, inspect the wrapped error for syscall.EACCES or ENOSPC and surface a targeted message (permissions vs. disk-full) instead of the generic copy error.","preventionTips":["Run Hugo as a user with write access to public/.","Clean the publish dir between builds in CI to avoid stale-file locks.","On Windows, exclude the Hugo publish dir from anti-virus scanning."],"tags":["io","publish","batch","filesystem"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}