{"record":{"id":"eca7440c9a111823","repo":"kubernetes/kops","slug":"error-closing-temp-file-q-w","errorCode":null,"errorMessage":"error closing temp file %q: %w","messagePattern":"error closing temp file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/files.go","lineNumber":96,"sourceCode":"\t\t\t}\n\t\t}\n\t\tif deleteTempFile {\n\t\t\tif err := os.Remove(tempFile.Name()); err != nil {\n\t\t\t\tklog.Warningf(\"error removing tempfile %q: %v\", tempFile.Name(), err)\n\t\t\t}\n\t\t}\n\t}()\n\n\tif _, err := io.Copy(tempFile, in); err != nil {\n\t\treturn fmt.Errorf(\"error writing file %q: %v\", tempFile.Name(), err)\n\t}\n\n\tif err := tempFile.Chmod(fileMode); err != nil {\n\t\treturn fmt.Errorf(\"error setting mode on temp file %q: %w\", tempFile.Name(), err)\n\t}\n\n\tif err := tempFile.Close(); err != nil {\n\t\treturn fmt.Errorf(\"error closing temp file %q: %w\", tempFile.Name(), err)\n\t}\n\tcloseTempFile = false\n\n\tif err := os.Rename(tempFile.Name(), destPath); err != nil {\n\t\treturn fmt.Errorf(\"error renaming temp file %q -> %q: %w\", tempFile.Name(), destPath, err)\n\t}\n\tdeleteTempFile = false\n\n\treturn nil\n}\n\nfunc EnsureFileMode(destPath string, fileMode os.FileMode) (bool, error) {\n\tchanged := false\n\tstat, err := os.Lstat(destPath)\n\tif err != nil {\n\t\treturn changed, fmt.Errorf(\"error getting file mode for %q: %v\", destPath, err)\n\t}\n\tif (stat.Mode() & os.ModePerm) == fileMode {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/files.go#L78-L114","documentation":"Thrown by writeFileContents when closing the temp file after copying contents fails. A close error can flush pending writes, so it may indicate a delayed write error (disk full at flush time) or an invalidated descriptor; the code treats it as fatal before renaming into place.","triggerScenarios":"Thrown at upup/pkg/fi/files.go:96 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check disk space and filesystem health on the destination volume","Retry the write — transient close/flush errors on network filesystems are common","Inspect the wrapped error to confirm whether it is ENOSPC, EIO, or an already-closed descriptor"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}