Skip to content

Commit

Permalink
Adds a message to packit.Fail in detect
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt committed May 2, 2023
1 parent 53403cb commit 8c9c93a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package rake

import (
"fmt"
"os"
"path/filepath"

"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/fs"
)

type BuildPlanMetadata struct {
Expand All @@ -17,20 +17,19 @@ func Detect(gemfileParser Parser) packit.DetectFunc {
rakefiles := []string{"Rakefile", "Rakefile.rb", "rakefile", "rakefile.rb"}
rakeFileExists := false
for _, file := range rakefiles {
_, err := os.Stat(filepath.Join(context.WorkingDir, file))
exists, err := fs.Exists(filepath.Join(context.WorkingDir, file))
if err != nil {
if os.IsNotExist(err) {
continue
}
return packit.DetectResult{}, fmt.Errorf("failed to stat %s: %w", file, err)
} else {
}

if exists {
rakeFileExists = true
break
}
}

if !rakeFileExists {
return packit.DetectResult{}, packit.Fail
return packit.DetectResult{}, packit.Fail.WithMessage("no 'Rakefile', 'Rakefile.rb', 'rakefile', or 'rakefile.rb' file found")
}

hasRakeGem, err := gemfileParser.Parse(filepath.Join(context.WorkingDir, "Gemfile"))
Expand Down
2 changes: 1 addition & 1 deletion detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
_, err := detect(packit.DetectContext{
WorkingDir: workingDir,
})
Expect(err).To(MatchError(packit.Fail))
Expect(err).To(MatchError(packit.Fail.WithMessage("no 'Rakefile', 'Rakefile.rb', 'rakefile', or 'rakefile.rb' file found")))
})
})

Expand Down

0 comments on commit 8c9c93a

Please sign in to comment.