This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new d50322e chore(cli): Fix error handling in local commands
d50322e is described below
commit d50322eff78c607c8c654a2e6c5a87185854d68e
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Mon Apr 12 11:59:13 2021 +0200
chore(cli): Fix error handling in local commands
---
pkg/cmd/local_build.go | 10 +++++-----
pkg/cmd/local_run.go | 11 ++++++-----
pkg/cmd/util_dependencies.go | 19 ++++++++++++++-----
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/pkg/cmd/local_build.go b/pkg/cmd/local_build.go
index 2e42194..b9606dd 100644
--- a/pkg/cmd/local_build.go
+++ b/pkg/cmd/local_build.go
@@ -20,9 +20,10 @@ package cmd
import (
"fmt"
- "github.com/apache/camel-k/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
+
+ "github.com/apache/camel-k/pkg/util"
)
func newCmdLocalBuild(rootCmdOptions *RootCmdOptions) (*cobra.Command,
*localBuildCmdOptions) {
@@ -105,7 +106,7 @@ func (command *localBuildCmdOptions) validate(args
[]string) error {
// Validate properties file.
err = validateFiles(command.PropertyFiles)
if err != nil {
- return nil
+ return err
}
// ContainerRegistry should only be specified when building the base
image.
@@ -163,8 +164,7 @@ func (command *localBuildCmdOptions) init(args []string)
error {
}
func (command *localBuildCmdOptions) run(cmd *cobra.Command, args []string)
error {
- dependenciesList := []string{}
- propertyFilesList := []string{}
+ var dependenciesList, propertyFilesList []string
routeFiles := args
if !command.BaseImage {
// Fetch dependencies.
@@ -173,7 +173,7 @@ func (command *localBuildCmdOptions) run(cmd
*cobra.Command, args []string) erro
return err
}
- propertyFiles := []string{}
+ var propertyFiles []string
if !command.DependenciesOnly {
// Manage integration properties which may come from
files or CLI.
propertyFiles, err =
updateIntegrationProperties(command.Properties, command.PropertyFiles, false)
diff --git a/pkg/cmd/local_run.go b/pkg/cmd/local_run.go
index 3e51d35..db8c4b4 100644
--- a/pkg/cmd/local_run.go
+++ b/pkg/cmd/local_run.go
@@ -20,9 +20,10 @@ package cmd
import (
"fmt"
- "github.com/apache/camel-k/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
+
+ "github.com/apache/camel-k/pkg/util"
)
func newCmdLocalRun(rootCmdOptions *RootCmdOptions) (*cobra.Command,
*localRunCmdOptions) {
@@ -146,7 +147,7 @@ func (command *localRunCmdOptions) run(cmd *cobra.Command,
args []string) error
hasIntegrationDir := command.IntegrationDirectory != ""
- dependencies := []string{}
+ var dependencies []string
if hasIntegrationDir {
localBuildDependencies, err :=
getLocalBuildDependencies(command.IntegrationDirectory)
if err != nil {
@@ -201,13 +202,13 @@ func (command *localRunCmdOptions) run(cmd
*cobra.Command, args []string) error
return err
}
} else {
- propertieDir := util.GetLocalPropertiesDir()
+ propertiesDir := util.GetLocalPropertiesDir()
if hasIntegrationDir {
- propertieDir =
getCustomPropertiesDir(command.IntegrationDirectory)
+ propertiesDir =
getCustomPropertiesDir(command.IntegrationDirectory)
}
// Run integration locally.
- err := RunLocalIntegrationRunCommand(command.Context,
propertyFiles, dependencies, routes, propertieDir, cmd.OutOrStdout(),
cmd.ErrOrStderr())
+ err := RunLocalIntegrationRunCommand(command.Context,
propertyFiles, dependencies, routes, propertiesDir, cmd.OutOrStdout(),
cmd.ErrOrStderr())
if err != nil {
return err
}
diff --git a/pkg/cmd/util_dependencies.go b/pkg/cmd/util_dependencies.go
index 0dbbcb1..be0dfb7 100644
--- a/pkg/cmd/util_dependencies.go
+++ b/pkg/cmd/util_dependencies.go
@@ -311,7 +311,7 @@ func validateFiles(args []string) error {
for _, arg := range args {
err := validateFile(arg)
if err != nil {
- return nil
+ return err
}
}
@@ -354,7 +354,7 @@ func validateIntegrationFiles(args []string) error {
// Validate integration files.
err := validateFiles(args)
if err != nil {
- return nil
+ return err
}
return nil
@@ -388,7 +388,10 @@ func updateIntegrationProperties(properties []string,
propertyFiles []string, ha
var relocatedPropertyFiles []string
for _, propertyFile := range propertyFiles {
relocatedPropertyFile :=
path.Join(util.GetLocalPropertiesDir(), path.Base(propertyFile))
- util.CopyFile(propertyFile, relocatedPropertyFile)
+ _, err = util.CopyFile(propertyFile, relocatedPropertyFile)
+ if err != nil {
+ return nil, err
+ }
relocatedPropertyFiles = append(relocatedPropertyFiles,
relocatedPropertyFile)
}
@@ -424,7 +427,10 @@ func updateIntegrationDependencies(dependencies []string)
error {
} else {
targetPath = path.Join(util.GetLocalDependenciesDir(),
path.Base(dependency))
}
- util.CopyFile(dependency, targetPath)
+ _, err = util.CopyFile(dependency, targetPath)
+ if err != nil {
+ return err
+ }
}
return nil
@@ -437,7 +443,10 @@ func updateIntegrationRoutes(routes []string) error {
}
for _, route := range routes {
- util.CopyFile(route, path.Join(util.GetLocalRoutesDir(),
path.Base(route)))
+ _, err = util.CopyFile(route,
path.Join(util.GetLocalRoutesDir(), path.Base(route)))
+ if err != nil {
+ return err
+ }
}
return nil