From 9f8a286979f4c35fe54fa33e2d9a34992718d6ba Mon Sep 17 00:00:00 2001 From: Marek Aufart Date: Wed, 2 Oct 2024 21:30:00 +0200 Subject: [PATCH] :bug: Handle missing containerless-deps (#349) * Handle missing containerless-deps Missing container-kantra-deps setup caused kantra analyze-bin command segfault. Adding check and error message to fail nicely. Related to: https://github.com/konveyor/kantra/pull/338 Signed-off-by: Marek Aufart * Update .kantra subdirs validation Signed-off-by: Marek Aufart * Update RulesetsLocation path from const Signed-off-by: Marek Aufart --------- Signed-off-by: Marek Aufart --- cmd/analyze-bin.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/analyze-bin.go b/cmd/analyze-bin.go index b07747b..c5351f1 100644 --- a/cmd/analyze-bin.go +++ b/cmd/analyze-bin.go @@ -286,6 +286,16 @@ func NewAnalyzeBinCmd(log logr.Logger) *cobra.Command { } func (b *analyzeBinCommand) Validate(ctx context.Context) error { + // Validate .kantra in home directory and its content (containerless) + requiredDirs := []string{b.homeKantraDir, filepath.Join(b.homeKantraDir, RulesetsLocation), filepath.Join(b.homeKantraDir, JavaBundlesLocation), filepath.Join(b.homeKantraDir, JDTLSBinLocation)} + for _, path := range requiredDirs { + if _, err := os.Stat(path); os.IsNotExist(err) { + b.log.Error(err, "cannot open required path, ensure that container-less dependencies are installed") + return err + } + } + + // Print-only methods if b.listSources || b.listTargets { return nil } @@ -430,6 +440,10 @@ func (b *analyzeBinCommand) fetchLabels(ctx context.Context, listSources, listTa func (b *analyzeBinCommand) walkRuleFilesForLabels(label string) ([]string, error) { labelsSlice := []string{} path := filepath.Join(b.homeKantraDir, RulesetsLocation) + if _, err := os.Stat(path); os.IsNotExist(err) { + b.log.Error(err, "cannot open provided path") + return nil, err + } err := filepath.WalkDir(path, walkRuleSets(path, label, &labelsSlice)) if err != nil { return nil, err