{"record":{"id":"e76096343db4d9bf","repo":"GoogleContainerTools/skaffold","slug":"writing-real-file-q-w","errorCode":null,"errorMessage":"writing real file %q: %w","messagePattern":"writing real file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/util/tar.go","lineNumber":205,"sourceCode":"\t\treturn err\n\t}\n\tif mode.IsRegular() {\n\t\tf, err := os.Open(src)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer f.Close()\n\n\t\tif ctx.Err() != nil {\n\t\t\treturn ctx.Err()\n\t\t}\n\n\t\t// Wrap the tar.Writer in a cancelableWriter that checks the context\n\t\tcw := &cancelableWriter{w: tw, ctx: ctx}\n\n\t\t// Proceed with copying the file content using the cancelable writer\n\t\tif _, err := io.Copy(cw, f); err != nil {\n\t\t\treturn fmt.Errorf(\"writing real file %q: %w\", src, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// Code copied from https://github.com/moby/moby/blob/master/pkg/archive/archive_windows.go\nfunc chmodTarEntry(perm os.FileMode) os.FileMode {\n\t// perm &= 0755 // this 0-ed out tar flags (like link, regular file, directory marker etc.)\n\tpermPart := perm & os.ModePerm\n\tnoPermPart := perm &^ os.ModePerm\n\t// Add the x bit: make everything +x from windows\n\tpermPart |= 0111\n\tpermPart &= 0755\n\n\treturn noPermPart | permPart\n}\n","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/util/tar.go#L187-L223","documentation":"This error wraps any failure that occurs while streaming a regular file's contents into a tar archive via io.Copy in addFileToTar. The copy runs through a cancelableWriter that aborts when the context is canceled, so the wrapped error is either an underlying read/write I/O failure or ctx.Err() (e.g. context canceled). Skaffold surfaces it while building tar-based artifacts (CreateTar, CreateMappedTar, CreateTarWithParents).","triggerScenarios":"Calling CreateTar/CreateMappedTar/CreateTarWithParents on a source file that shrinks or becomes unreadable mid-copy, a disk-full or I/O error on the tar writer's destination, or the passed context being canceled while io.Copy is streaming the file bytes.","commonSituations":"Files deleted or truncated by another process (or a rebuild) while the tar is being assembled; the user hits Ctrl-C so the context cancels partway through copying; out-of-space on the output volume; network filesystems dropping mid-read.","solutions":["Re-run the command; a transient I/O hiccup or intentional Ctrl-C cancel is the most common cause.","Verify the source file still exists, is readable, and is stable (not being rewritten) during archiving.","Check free disk space on the volume receiving the tar output.","If canceled programmatically, extend or remove the context deadline/timeout around the tar operation."],"exampleFix":"// before\nerr := util.CreateTar(ctx, tmpdir, deps.Dependencies)\n// after\nif ctx.Err() != nil {\n    return fmt.Errorf(\"context already canceled, skipping tar: %w\", ctx.Err())\n}\nif err := util.CreateTar(ctx, tmpdir, deps.Dependencies); err != nil {\n    log.Entry(ctx).Warnf(\"tar failed (%v); retrying once\", err)\n    err = util.CreateTar(context.WithoutCancel(ctx), tmpdir, deps.Dependencies)\n}","handlingStrategy":"try-catch","validationCode":"// before archiving\nif _, err := os.Stat(src); err != nil {\n    return fmt.Errorf(\"source unreadable: %w\", err)\n}\nif err := ctx.Err(); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := util.CreateTar(ctx, tmp, deps); err != nil {\n    var ctxErr = context.Canceled\n    if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n        // user cancel / timeout: treat as expected\n        return err\n    }\n    // transient I/O: retry once\n    return util.CreateTar(context.WithoutCancel(ctx), tmp, deps)\n}","preventionTips":["Ensure source files are not modified/deleted while the tar is being created (freeze rebuilds during archive).","Check free disk space on the output volume before large archives.","Wrap long tar operations with an adequate context timeout and handle Ctrl-C gracefully.","Pre-open/stat every dependency file to fail fast on unreadable inputs."],"tags":["tar","io","filesystem","context-canceled"],"backgroundTag":"tar-write-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}