{"record":{"id":"983b48ff61ddf52a","repo":"ipfs/kubo","slug":"file-rename-error-s-file-remove-error-s","errorCode":null,"errorMessage":"file Rename error: %s, file remove error: %s","messagePattern":"file Rename error: (.+?), file remove error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/fsrepo/fsrepo.go","lineNumber":410,"sourceCode":"\t\treturn err\n\t}\n\n\tif _, err = f.WriteString(addr.String()); err != nil {\n\t\tf.Close()\n\t\treturn err\n\t}\n\tif err = f.Close(); err != nil {\n\t\treturn err\n\t}\n\n\t// Atomically rename the temp file to the correct file name.\n\tif err = os.Rename(filepath.Join(r.path, \".\"+apiFile+\".tmp\"), filepath.Join(r.path,\n\t\tapiFile)); err == nil {\n\t\treturn nil\n\t}\n\t// Remove the temp file when rename return error\n\tif err1 := os.Remove(filepath.Join(r.path, \".\"+apiFile+\".tmp\")); err1 != nil {\n\t\treturn fmt.Errorf(\"file Rename error: %s, file remove error: %s\", err.Error(),\n\t\t\terr1.Error())\n\t}\n\treturn err\n}\n\n// SetGatewayAddr writes the Gateway Addr to the /gateway file.\nfunc (r *FSRepo) SetGatewayAddr(addr net.Addr) error {\n\t// Create a temp file to write the address, so that we don't leave empty file when the\n\t// program crashes after creating the file.\n\ttmpPath := filepath.Join(r.path, \".\"+gatewayFile+\".tmp\")\n\tf, err := os.Create(tmpPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar good bool\n\t// Silently remove as worst last case with defers.\n\tdefer func() {\n\t\tif !good {","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/repo/fsrepo/fsrepo.go#L392-L428","documentation":"While writing the daemon's API address file: the atomic rename of the temp file to 'api' failed AND the cleanup removal of the temp file also failed; both errors are reported so no orphaned temp file is left silently.","triggerScenarios":"Thrown at repo/fsrepo/fsrepo.go:410 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the leftover '.api.tmp' file in the repo directory","Check filesystem permissions and that the repo is not on a broken mount","Restart the daemon to retry writing the API address"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}