diff options
| author | 2023-01-23 14:04:24 -0500 | |
|---|---|---|
| committer | 2023-01-24 10:39:07 -0500 | |
| commit | ce39f83538f26c23a4d939a5e8d60083d616aee4 (patch) | |
| tree | 453c16f37b3ecc52311b9cdf79f039a9205f907f | |
| parent | 2d0349f1335acbd80748c3699d7ddba6c1972598 (diff) | |
add error handling to cquery in MockBazelContext
Change-Id: Ia01072b6528caff2f3ceaca67cdba8b900924fe5
| -rw-r--r-- | android/bazel_handler.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/android/bazel_handler.go b/android/bazel_handler.go index 8d4504175..4a495f02e 100644 --- a/android/bazel_handler.go +++ b/android/bazel_handler.go @@ -233,27 +233,42 @@ func (m MockBazelContext) QueueBazelRequest(_ string, _ cqueryRequest, _ configK } func (m MockBazelContext) GetOutputFiles(label string, _ configKey) ([]string, error) { - result, _ := m.LabelToOutputFiles[label] + result, ok := m.LabelToOutputFiles[label] + if !ok { + return []string{}, fmt.Errorf("no target with label %q in LabelToOutputFiles", label) + } return result, nil } func (m MockBazelContext) GetCcInfo(label string, _ configKey) (cquery.CcInfo, error) { - result, _ := m.LabelToCcInfo[label] + result, ok := m.LabelToCcInfo[label] + if !ok { + return cquery.CcInfo{}, fmt.Errorf("no target with label %q in LabelToCcInfo", label) + } return result, nil } func (m MockBazelContext) GetPythonBinary(label string, _ configKey) (string, error) { - result, _ := m.LabelToPythonBinary[label] + result, ok := m.LabelToPythonBinary[label] + if !ok { + return "", fmt.Errorf("no target with label %q in LabelToPythonBinary", label) + } return result, nil } func (m MockBazelContext) GetApexInfo(label string, _ configKey) (cquery.ApexInfo, error) { - result, _ := m.LabelToApexInfo[label] + result, ok := m.LabelToApexInfo[label] + if !ok { + return cquery.ApexInfo{}, fmt.Errorf("no target with label %q in LabelToApexInfo", label) + } return result, nil } func (m MockBazelContext) GetCcUnstrippedInfo(label string, _ configKey) (cquery.CcUnstrippedInfo, error) { - result, _ := m.LabelToCcBinary[label] + result, ok := m.LabelToCcBinary[label] + if !ok { + return cquery.CcUnstrippedInfo{}, fmt.Errorf("no target with label %q in LabelToCcBinary", label) + } return result, nil } |