From 837b28e4aa063151b2b86bb1f7652868c35d39b1 Mon Sep 17 00:00:00 2001 From: Ayaz Badouraly Date: Sun, 9 Apr 2023 22:39:29 +0200 Subject: [PATCH] Add debug logs for https://github.com/google/yamlfmt/issues/97 --- command/command.go | 8 ++++++++ path_collector.go | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/command/command.go b/command/command.go index 4cf6680..3916aa1 100644 --- a/command/command.go +++ b/command/command.go @@ -113,13 +113,16 @@ func (c *Command) Run() error { collectedPaths, err := c.collectPaths() if err != nil { + fmt.Printf("[DEBUG ISSUE 97] collect paths returned err=%#v\n", err) return err } + fmt.Printf("[DEBUG ISSUE 97] collect paths returned collectedPaths=%#v\n", collectedPaths) paths, err := c.analyzePaths(collectedPaths) if err != nil { log.Printf("path analysis found the following errors:\n%v", err) log.Println("Continuing...") } + fmt.Printf("[DEBUG ISSUE 97] analyze paths returned paths=%#v\n", paths) switch c.Operation { case OperationFormat: @@ -164,7 +167,12 @@ func (c *Command) Run() error { } func (c *Command) collectPaths() ([]string, error) { + fmt.Printf("[DEBUG ISSUE 97] c.Config=%#v\n", c.Config) + fmt.Printf("[DEBUG ISSUE 97] c.Config.FormatterConfig=%#v\n", c.Config.FormatterConfig) + collector := c.makePathCollector() + fmt.Printf("[DEBUG ISSUE 97] collector=%#v\n", collector) + return collector.CollectPaths() } diff --git a/path_collector.go b/path_collector.go index 2f9fa68..7547bb4 100644 --- a/path_collector.go +++ b/path_collector.go @@ -1,6 +1,7 @@ package yamlfmt import ( + "fmt" "io/fs" "log" "os" @@ -22,6 +23,7 @@ type FilepathCollector struct { } func (c *FilepathCollector) CollectPaths() ([]string, error) { + fmt.Printf("[DEBUG ISSUE 97] entered filepath collector\n") pathsFound := []string{} for _, inclPath := range c.Include { info, err := os.Stat(inclPath) @@ -99,18 +101,22 @@ type DoublestarCollector struct { } func (c *DoublestarCollector) CollectPaths() ([]string, error) { + fmt.Printf("[DEBUG ISSUE 97] entered doublestar collector\n") includedPaths := []string{} for _, pattern := range c.Include { globMatches, err := doublestar.FilepathGlob(pattern) if err != nil { + fmt.Printf("[DEBUG ISSUE 97] filepath glob returned err=%#v\n", includedPaths) return nil, err } includedPaths = append(includedPaths, globMatches...) } + fmt.Printf("[DEBUG ISSUE 97] includedPaths=%#v\n", includedPaths) pathsToFormatSet := collections.Set[string]{} for _, path := range includedPaths { if len(c.Exclude) == 0 { + fmt.Printf("[DEBUG ISSUE 97] included because empty exclude path=%#v\n", path) pathsToFormatSet.Add(path) continue } @@ -124,13 +130,17 @@ func (c *DoublestarCollector) CollectPaths() ([]string, error) { } match, err := doublestar.PathMatch(filepath.Clean(pattern), absPath) if err != nil { + fmt.Printf("[DEBUG ISSUE 97] path match returned err=%#v\n", err) return nil, err } if match { + fmt.Printf("[DEBUG ISSUE 97] excluded because of pattern=%#v absPath=%#v\n", pattern, absPath) excluded = true } + fmt.Printf("[DEBUG ISSUE 97] no match pattern=%#v absPath=%#v\n", pattern, absPath) } if !excluded { + fmt.Printf("[DEBUG ISSUE 97] included because not excluded path=%#v\n", path) pathsToFormatSet.Add(path) } }