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.
This commit is contained in:
Eitol 2024-07-10 11:11:34 -04:00
parent 2cc9781522
commit 414ffa3a2c
1 changed files with 2 additions and 1 deletions

View File

@ -327,10 +327,11 @@ func WriteProtoFiles(outProtoDirPath string, descSource DescriptorSource, symbol
} }
return fmt.Errorf("failed to create file %q: %v", filePath, err) return fmt.Errorf("failed to create file %q: %v", filePath, err)
} }
_ = f.Close()
if err := pr.PrintProtoFile(fd, f); err != nil { if err := pr.PrintProtoFile(fd, f); err != nil {
_ = f.Close()
return fmt.Errorf("failed to write file %q: %v", filePath, err) return fmt.Errorf("failed to write file %q: %v", filePath, err)
} }
_ = f.Close()
} }
return nil return nil
} }