Refactor error handling in file creation
The code responsible for error handling during file creation in the desc_source.go file has been streamlined. This modification simplifies the code by reducing unnecessary condition checks and redundant file closure action after an error has occurred.
This commit is contained in:
parent
9706903f6e
commit
21c947e107
|
|
@ -322,16 +322,14 @@ func WriteProtoFiles(outProtoDirPath string, descSource DescriptorSource, symbol
|
||||||
filePath := filepath.Join(outFilepath, fileName)
|
filePath := filepath.Join(outFilepath, fileName)
|
||||||
f, err := os.Create(filePath)
|
f, err := os.Create(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if f != nil {
|
|
||||||
_ = f.Close()
|
|
||||||
}
|
|
||||||
return fmt.Errorf("failed to create file %q: %v", filePath, err)
|
return fmt.Errorf("failed to create file %q: %v", filePath, err)
|
||||||
}
|
}
|
||||||
if err := pr.PrintProtoFile(fd, f); err != nil {
|
err = pr.PrintProtoFile(fd, f)
|
||||||
|
if err == nil {
|
||||||
_ = f.Close()
|
_ = f.Close()
|
||||||
|
} else {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue