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:
parent
2cc9781522
commit
414ffa3a2c
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue