This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch release-1.3.x in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/release-1.3.x by this push: new d8d54c6 fix(cli): check run sources exists d8d54c6 is described below commit d8d54c67eaac9f1fb7485db32d4dcec20b3e85aa Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Fri Jan 15 10:33:34 2021 +0100 fix(cli): check run sources exists * Changed the name of run.isLocal func to run.isLocalAndExists as the function does both things * Added a default switch case to report either the file doesn't exist or the URI scheme cannot be parsed * Added some unit test to verify error messages expected Fixes #1911 --- pkg/cmd/run.go | 4 ++-- pkg/cmd/util_content.go | 2 +- pkg/cmd/util_sources.go | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 5904272..695f01f 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -380,7 +380,7 @@ func (o *runCmdOptions) syncIntegration(cmd *cobra.Command, c client.Client, sou files = append(files, o.OpenAPIs...) for _, s := range files { - if isLocal(s) { + if isLocalAndFileExists(s) { changes, err := sync.File(o.Context, s) if err != nil { return err @@ -645,7 +645,7 @@ func (*runCmdOptions) configureTraits(integration *v1.Integration, options []str return nil } -func isLocal(fileName string) bool { +func isLocalAndFileExists(fileName string) bool { info, err := os.Stat(fileName) if os.IsNotExist(err) { return false diff --git a/pkg/cmd/util_content.go b/pkg/cmd/util_content.go index 75d9c08..c210870 100644 --- a/pkg/cmd/util_content.go +++ b/pkg/cmd/util_content.go @@ -30,7 +30,7 @@ func loadContent(source string, compress bool, compressBinary bool) (string, boo var content []byte var err error - if isLocal(source) { + if isLocalAndFileExists(source) { content, err = ioutil.ReadFile(source) } else { u, err := url.Parse(source) diff --git a/pkg/cmd/util_sources.go b/pkg/cmd/util_sources.go index 50a0838..f539705 100644 --- a/pkg/cmd/util_sources.go +++ b/pkg/cmd/util_sources.go @@ -65,7 +65,7 @@ func ResolveSources(ctx context.Context, locations []string, compress bool) ([]S sources := make([]Source, 0, len(locations)) for _, location := range locations { - if isLocal(location) { + if isLocalAndFileExists(location) { answer, err := ResolveLocalSource(location, compress) if err != nil { return sources, err @@ -176,6 +176,8 @@ func ResolveSources(ctx context.Context, locations []string, compress bool) ([]S return sources, err } sources = append(sources, answer) + default: + return sources, fmt.Errorf("Missing file or unsupported scheme in %s", location) } } }