From 37fbe81e7e909635231f9e9d39be37814d0a8f05 Mon Sep 17 00:00:00 2001 From: Luke Kingland Date: Thu, 17 Nov 2022 14:01:11 +0900 Subject: [PATCH] error handling cleanup --- cmd/build.go | 19 +++++++++---------- cmd/deploy.go | 21 ++++++++------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/cmd/build.go b/cmd/build.go index efd3489cc3..17c9a40be0 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -116,24 +116,23 @@ and the image name is stored in the configuration file. } func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err error) { - if err = config.CreatePaths(); err != nil { - return // see docker/creds potential mutation of auth.json + var ( + cfg buildConfig + f fn.Function + ) + if err = config.CreatePaths(); err != nil { // for possible auth.json usage + return } - - cfg, err := newBuildConfig().Prompt() - if err != nil { + if cfg, err = newBuildConfig().Prompt(); err != nil { return } - if err = cfg.Validate(); err != nil { return } - - f, err := fn.NewFunction(cfg.Path) - if err != nil { + if f, err = fn.NewFunction(cfg.Path); err != nil { return } - f = cfg.Configure(f) // Updates f at path to include build request values + f = cfg.Configure(f) // Updates f with build cfg // Checks if there is a difference between defined registry and its value used as a prefix in the image tag // In case of a mismatch a new image tag is created and used for build diff --git a/cmd/deploy.go b/cmd/deploy.go index 53202e335e..01831ba0a9 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -203,28 +203,23 @@ EXAMPLES } func runDeploy(cmd *cobra.Command, _ []string, newClient ClientFactory) (err error) { - if err = config.CreatePaths(); err != nil { - return // see docker/creds potential mutation of auth.json - } - - cfg, err := newDeployConfig(cmd).Prompt() - if err != nil { + var ( + cfg deployConfig + f fn.Function + ) + if err = config.CreatePaths(); err != nil { // for possible auth.json usage return } - - if cfg, err = cfg.Prompt(); err != nil { + if cfg, err = newDeployConfig(cmd).Prompt(); err != nil { return } - if err = cfg.Validate(); err != nil { return } - - f, err := fn.NewFunction(cfg.Path) - if err != nil { + if f, err = fn.NewFunction(cfg.Path); err != nil { return } - if f, err = cfg.Configure(f); err != nil { // Updates f at path to include deploy request values + if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg return }