{"id":"a5980a36609c6478","repo":"docker/cli","slug":"error-closing-temp-file-w","errorCode":null,"errorMessage":"error closing temp file: %w","messagePattern":"error closing temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/config/configfile/file.go","lineNumber":226,"sourceCode":"\t\treturn err\n\t}\n\tdefer func() {\n\t\t// ignore error as the file may already be closed when we reach this.\n\t\t_ = temp.Close()\n\t\tif retErr != nil {\n\t\t\tif err := os.Remove(temp.Name()); err != nil {\n\t\t\t\tlogrus.WithError(err).WithField(\"file\", temp.Name()).Debug(\"Error cleaning up temp file\")\n\t\t\t}\n\t\t}\n\t}()\n\n\terr = c.SaveToWriter(temp)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err := temp.Close(); err != nil {\n\t\treturn fmt.Errorf(\"error closing temp file: %w\", err)\n\t}\n\n\t// Handle situation where the configfile is a symlink, and allow for dangling symlinks\n\tcfgFile := c.Filename\n\tif f, err := filepath.EvalSymlinks(cfgFile); err == nil {\n\t\tcfgFile = f\n\t} else if os.IsNotExist(err) {\n\t\t// extract the path from the error if the configfile does not exist or is a dangling symlink\n\t\tvar pathError *os.PathError\n\t\tif errors.As(err, &pathError) {\n\t\t\tcfgFile = pathError.Path\n\t\t}\n\t}\n\n\t// Try copying the current config file (if any) ownership and permissions\n\tcopyFilePermissions(cfgFile, temp.Name())\n\treturn os.Rename(temp.Name(), cfgFile)\n}","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/config/configfile/file.go#L208-L244","documentation":"Error \"error closing temp file: %w\" thrown in docker/cli.","triggerScenarios":"Thrown at cli/config/configfile/file.go:226 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}