Skip to content

Commit

Permalink
Add context to error messages (#34)
Browse files Browse the repository at this point in the history
* Add context to error messages

* Fix double prefix

* Capitalize error strings
  • Loading branch information
ofalvai authored Feb 23, 2022
1 parent ca14557 commit f6fe0b8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func failf(f string, args ...interface{}) {
}

func getArtifacts(gradleProject gradle.Project, started time.Time, pattern string, includeModuleName bool, isDirectoryMode bool) (artifacts []gradle.Artifact, err error) {
for _, t := range []time.Time{started, time.Time{}} {
for _, t := range []time.Time{started, {}} {
if isDirectoryMode {
artifacts, err = gradleProject.FindDirs(t, pattern, includeModuleName)
} else {
Expand Down Expand Up @@ -126,7 +126,7 @@ func filterVariants(module, variant string, variantsMap gradle.Variants) (gradle
}
}
if len(filteredVariants) == 0 {
return nil, fmt.Errorf("variant: %s not found in any module", variant)
return nil, fmt.Errorf("variant %s not found in any module", variant)
}
return filteredVariants, nil
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func main() {
var config Configs

if err := stepconf.Parse(&config); err != nil {
failf("Couldn't create step config: %v\n", err)
failf("Process config: couldn't create step config: %v\n", err)
}

stepconf.Print(config)
Expand All @@ -169,27 +169,27 @@ func main() {

gradleProject, err := gradle.NewProject(config.ProjectLocation, cmdFactory)
if err != nil {
failf("Failed to open project, error: %s", err)
failf("Process config: failed to open project, error: %s", err)
}

testTask := gradleProject.GetTask("test")

args, err := shellquote.Split(config.Arguments)
if err != nil {
failf("Failed to parse arguments, error: %s", err)
failf("Process config: failed to parse arguments, error: %s", err)
}

logger.Infof("Variants:")
fmt.Println()

variants, err := testTask.GetVariants(args...)
if err != nil {
failf("Failed to fetch variants, error: %s", err)
failf("Run: failed to fetch variants, error: %s", err)
}

filteredVariants, err := filterVariants(config.Module, config.Variant, variants)
if err != nil {
failf("Failed to find buildable variants, error: %s", err)
failf("Run: failed to find buildable variants, error: %s", err)
}

for module, variants := range variants {
Expand Down Expand Up @@ -217,19 +217,19 @@ func main() {

testErr = testCommand.Run()
if testErr != nil {
logger.Errorf("Test task failed, error: %v", testErr)
logger.Errorf("Run: test task failed, error: %v", testErr)
}
fmt.Println()
logger.Infof("Export HTML results:")
fmt.Println()

reports, err := getArtifacts(gradleProject, started, config.HTMLResultDirPattern, true, true)
if err != nil {
failf("Failed to find reports, error: %v", err)
failf("Export outputs: failed to find reports, error: %v", err)
}

if err := exportArtifacts(config.DeployDir, reports); err != nil {
failf("Failed to export reports, error: %v", err)
failf("Export outputs: failed to export reports, error: %v", err)
}

fmt.Println()
Expand All @@ -238,11 +238,11 @@ func main() {

results, err := getArtifacts(gradleProject, started, config.XMLResultDirPattern, true, true)
if err != nil {
failf("Failed to find results, error: %v", err)
failf("Export outputs: failed to find results, error: %v", err)
}

if err := exportArtifacts(config.DeployDir, results); err != nil {
failf("Failed to export results, error: %v", err)
failf("Export outputs: failed to export results, error: %v", err)
}

if config.TestResultDir != "" {
Expand Down

0 comments on commit f6fe0b8

Please sign in to comment.