diff --git a/resolvers.go b/resolvers.go index 24801c4..39bb60b 100644 --- a/resolvers.go +++ b/resolvers.go @@ -111,6 +111,9 @@ type ArtifactResolver struct { // InterestingFileDetector is used to determine if a file is a candidate for artifact resolution. InterestingFileDetector InterestingFileDetector + + // AdditionalHelpMessage can be used to supply context specific instructions if no matching artifact is found + AdditionalHelpMessage string } // Pattern returns the glob that ArtifactResolver will use for resolution. @@ -153,7 +156,11 @@ func (a *ArtifactResolver) Resolve(applicationPath string) (string, error) { } sort.Strings(artifacts) - return "", fmt.Errorf("unable to find single built artifact in %s, candidates: %s", pattern, candidates) + helpMsg := fmt.Sprintf("unable to find single built artifact in %s, candidates: %s", pattern, candidates) + if len(a.AdditionalHelpMessage) > 0 { + helpMsg = fmt.Sprintf("%s. %s", helpMsg, a.AdditionalHelpMessage) + } + return "", fmt.Errorf(helpMsg) } // ResolveArguments resolves the arguments that should be passed to a build system. diff --git a/resolvers_test.go b/resolvers_test.go index f2e7d16..98aa5b2 100644 --- a/resolvers_test.go +++ b/resolvers_test.go @@ -123,6 +123,19 @@ func testResolvers(t *testing.T, context spec.G, it spec.S) { filepath.Join(path, "test-file-1"), filepath.Join(path, "test-file-2")))) }) + it("fails with multiple candidates and provides extra help", func() { + Expect(ioutil.WriteFile(filepath.Join(path, "test-file-1"), []byte{}, 0644)).To(Succeed()) + Expect(ioutil.WriteFile(filepath.Join(path, "test-file-2"), []byte{}, 0644)).To(Succeed()) + detector.On("Interesting", mock.Anything).Return(true, nil) + + resolver.AdditionalHelpMessage = "Some more help." + + _, err := resolver.Resolve(path) + + Expect(err).To(MatchError(fmt.Sprintf("unable to find single built artifact in test-*, candidates: [%s %s]. Some more help.", + filepath.Join(path, "test-file-1"), filepath.Join(path, "test-file-2")))) + }) + context("$TEST_ARTIFACT_CONFIGURATION_KEY", func() { it.Before(func() { Expect(os.Setenv("TEST_ARTIFACT_CONFIGURATION_KEY", "another-file")).To(Succeed())