Skip to content

Commit

Permalink
error handling cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland committed Nov 17, 2022
1 parent 0a3cb6a commit 37fbe81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
19 changes: 9 additions & 10 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 8 additions & 13 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 37fbe81

Please sign in to comment.