mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
handle file close error
This commit is contained in:
parent
1377108c08
commit
84d29664c4
@ -334,7 +334,7 @@ func (o *Options) runLoop() error {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Options) writeConfigFile() error {
|
||||
func (o *Options) writeConfigFile() (err error) {
|
||||
const mediaType = runtime.ContentTypeYAML
|
||||
info, ok := runtime.SerializerInfoForMediaType(o.codecs.SupportedMediaTypes(), mediaType)
|
||||
if !ok {
|
||||
@ -347,10 +347,15 @@ func (o *Options) writeConfigFile() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO handle error
|
||||
defer configFile.Close()
|
||||
|
||||
if err := encoder.Encode(o.config, configFile); err != nil {
|
||||
defer func() {
|
||||
ferr := configFile.Close()
|
||||
if ferr != nil && err == nil {
|
||||
err = ferr
|
||||
}
|
||||
}()
|
||||
|
||||
if err = encoder.Encode(o.config, configFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user