Skip to content

Commit

Permalink
improve error messages in maven
Browse files Browse the repository at this point in the history
  • Loading branch information
emilwareus committed Dec 12, 2023
1 parent 666e57b commit 43566d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 10 additions & 5 deletions internal/resolution/pm/maven/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
nonParseablePomErrRegex = "Non-parseable POM (.*)"
networkUnreachableErrRegex = "Failed to retrieve plugin descriptor"
invalidVersionErrRegex = "('[\\w\\.]+' for [\\w\\.:-]+ must not contain any of these characters .* but found .)"
dependenciesResolveErrRegex = `Could not resolve dependencies for project`
dependenciesResolveErrRegex = `Could not resolve dependencies for project\s+([\w\.-]+:[\w\.-]+:[\w\.-]+:[\w\.-]+)`
)

type Job struct {
Expand Down Expand Up @@ -144,18 +144,23 @@ func (j *Job) addInvalidVersionErrorDocumentation(regex *regexp.Regexp, cmdErr j

func (j *Job) addDependenciesResolveErrorDocumentation(regex *regexp.Regexp, cmdErr job.IError) job.IError {
matches := regex.FindAllStringSubmatch(cmdErr.Error(), 1)
message := "An error occurred during dependencies resolve"
message := "An error occurred during dependencies resolve "
if len(matches) > 0 && len(matches[0]) > 1 {
message = matches[0][1]
message += strings.Join(
[]string{
"for: ",
matches[0][1],
"",
}, "")
}

cmdErr.SetDocumentation(
strings.Join(
[]string{
message,
"\nTry to run `mvn dependency:tree -e` to get more details.",
"\nTry to run `mvn dependency:tree -e` to get more details.\n",
util.InstallPrivateDependencyMessage,
}, " "),
}, ""),
)

return cmdErr
Expand Down
8 changes: 5 additions & 3 deletions internal/resolution/pm/maven/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestRunCmdErr(t *testing.T) {
},
{
error: " |[ERROR] Failed to execute goal on project jackpot: Could not resolve dependencies for project com.jeteo:jackpot:war:1.0-SNAPSHOT: The following artifacts could not be resolved: javax.servlet:com.springsource.javax.servlet:jar:2.5.0, javax.servlet:com.springsource.javax.servlet.jsp.jstl:jar:1.2.0 (http://repository.springsource.com/maven/bundles/release) -> [Help 1]\n",
doc: "Could not resolve dependencies for project com.jeteo:jackpot:war:1.0-SNAPSHOT: The following artifacts could not be resolved: javax.servlet:com.springsource.javax.servlet:jar:2.5.0, javax.servlet:com.springsource.javax.servlet.jsp.jstl:jar:1.2.0 \nTry to run `mvn dependency:tree -e` to get more details. If this is a private dependency, make sure you have access to install it.",
doc: "An error occurred during dependencies resolve for: com.jeteo:jackpot:war:1.0-SNAPSHOT\nTry to run `mvn dependency:tree -e` to get more details.\nIf this is a private dependency, please make sure that the debricked CLI has access to install it or pre-install it before running the debricked CLI.",
},
}

Expand All @@ -54,8 +54,10 @@ func TestRunCmdErr(t *testing.T) {

j.Run()

assert.Len(t, j.Errors().GetAll(), 1)
assert.Contains(t, j.Errors().GetAll(), expectedError)
errors := j.Errors().GetAll()

assert.Len(t, errors, 1)
assert.Contains(t, errors, expectedError)
}
}

Expand Down

0 comments on commit 43566d6

Please sign in to comment.