From a85a37e3f37b4164398dcb5d85c4aa49ba5b5d85 Mon Sep 17 00:00:00 2001 From: Will Wang Date: Wed, 24 Jul 2024 14:36:34 +0800 Subject: [PATCH] better to limit the scope of err Signed-off-by: Will Wang --- cli/config/configfile/file.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cli/config/configfile/file.go b/cli/config/configfile/file.go index 0e663aa162..0842431388 100644 --- a/cli/config/configfile/file.go +++ b/cli/config/configfile/file.go @@ -167,10 +167,9 @@ func (configFile *ConfigFile) Save() (retErr error) { return errors.Wrap(err, "error closing temp file") } - cfgFile := configFile.Filename // Handle situations where `configFile.Filename` is a symlink, and allow for dangling symlinks - f, err := filepath.EvalSymlinks(cfgFile) - if err == nil { + cfgFile := configFile.Filename + if f, err := filepath.EvalSymlinks(cfgFile); err == nil { cfgFile = f } else if os.IsNotExist(err) { // extract the path from the error if `cfgFile` does not exist or is a dangling symlink