From 973c90770839e2efa96331edbc93aa49eed724d0 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 8 Jun 2021 10:06:37 +0100 Subject: [PATCH] Improve error reporting when a rule cannot be found Outputs the list of available rules on separate lines. Bug: 179354495 Test: m nothing Merged-In: I845064e032f0a47d00883ff775c4f7b4fee7631e Change-Id: I845064e032f0a47d00883ff775c4f7b4fee7631e (cherry picked from commit 4dbf6cfbaec8b6ce7c6638cd455da89879d61d40) --- android/testing.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/android/testing.go b/android/testing.go index 191cb8d02..b36f62cce 100644 --- a/android/testing.go +++ b/android/testing.go @@ -713,9 +713,11 @@ func (b baseTestingComponent) newTestingBuildParams(bparams BuildParams) Testing func (b baseTestingComponent) maybeBuildParamsFromRule(rule string) (TestingBuildParams, []string) { var searchedRules []string - for _, p := range b.provider.BuildParamsForTests() { - searchedRules = append(searchedRules, p.Rule.String()) - if strings.Contains(p.Rule.String(), rule) { + buildParams := b.provider.BuildParamsForTests() + for _, p := range buildParams { + ruleAsString := p.Rule.String() + searchedRules = append(searchedRules, ruleAsString) + if strings.Contains(ruleAsString, rule) { return b.newTestingBuildParams(p), searchedRules } } @@ -725,7 +727,7 @@ func (b baseTestingComponent) maybeBuildParamsFromRule(rule string) (TestingBuil func (b baseTestingComponent) buildParamsFromRule(rule string) TestingBuildParams { p, searchRules := b.maybeBuildParamsFromRule(rule) if p.Rule == nil { - panic(fmt.Errorf("couldn't find rule %q.\nall rules: %v", rule, searchRules)) + panic(fmt.Errorf("couldn't find rule %q.\nall rules:\n%s", rule, strings.Join(searchRules, "\n"))) } return p }