From 414ffa3a2c19d155b07c04412188f8c7e347eac5 Mon Sep 17 00:00:00 2001 From: Eitol Date: Wed, 10 Jul 2024 11:11:34 -0400 Subject: [PATCH] Reorder file close operation in error handling The file close operation has been moved within the error handling of the 'PrintProtoFile' function. Previously, it was being executed before this function, now it's executed immediately after. Moreover, an additional close operation has been added after the function success ensuring the file is properly closed in all scenarios. --- desc_source.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/desc_source.go b/desc_source.go index 617839e..fd40b27 100644 --- a/desc_source.go +++ b/desc_source.go @@ -327,10 +327,11 @@ func WriteProtoFiles(outProtoDirPath string, descSource DescriptorSource, symbol } return fmt.Errorf("failed to create file %q: %v", filePath, err) } - _ = f.Close() if err := pr.PrintProtoFile(fd, f); err != nil { + _ = f.Close() return fmt.Errorf("failed to write file %q: %v", filePath, err) } + _ = f.Close() } return nil }