Skip to content

Commit

Permalink
fix: Generate error messages properly
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTatasciore committed Feb 22, 2022
1 parent a718bb9 commit a6fe115
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/aspect/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,7 @@ func (c *Clean) reclaimAll() error {
close(c.errorChannel)

if c.chanErrors.size > 0 {
// TODO: If there is more than one error do we want to combine them before returning?

return c.chanErrors.head.err
return c.chanErrors.generateError()
}

return nil
Expand Down Expand Up @@ -395,7 +393,7 @@ func (c *Clean) findBazelWorkspaces() {
continue
}

// We expect these folders to have up to 2 things
// We expect these folders to have up to 2 files / folders
// - Firstly, a file named "DO_NOT_BUILD_HERE"
// - Secondly, a folder named after the given workspace
// We can use the given second folder to determine the name of the workspace. We want this
Expand Down Expand Up @@ -532,7 +530,7 @@ func (c *Clean) findBazelBaseDir() (string, string, error) {

for _, file := range files {

// bazel-bin, bazel-out, etc... will be symlinks, so we can eliminate most files immediately
// bazel-bin, bazel-out, etc... will be symlinks, so we can eliminate non-symlinks immediately
if file.Mode()&os.ModeSymlink != 0 {
actualPath, _ := os.Readlink(cwd + "/" + file.Name())

Expand Down Expand Up @@ -639,6 +637,18 @@ type errorSet struct {
size int
}

func (s *errorSet) generateError() error {
var err error
for node := s.head; node != nil; node = node.next {
if err == nil {
err = node.err
} else {
err = fmt.Errorf("%s, %w", err, node.err)
}
}
return err
}

func (s *errorSet) insert(err error) {
node := errorNode{
err: err,
Expand Down

0 comments on commit a6fe115

Please sign in to comment.