go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/tryjob/requirement/errors.go (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package requirement 16 17 import ( 18 "fmt" 19 "strings" 20 ) 21 22 const canonicalDirectiveFormat = "project/bucket:builder1,builder2;project2/bucket:builder3" 23 24 // invalidTryjobDirectives is a computation failure where the value of the 25 // Tryjob directives provided in the footer is malformed. 26 type invalidTryjobDirectives struct { 27 value string 28 } 29 30 func (itd *invalidTryjobDirectives) Reason() string { 31 return fmt.Sprintf("The tryjob directive %q is invalid. Canonical format is %s", itd.value, canonicalDirectiveFormat) 32 } 33 34 // unauthorizedIncludedTryjob is a computation failure where a user is not 35 // allowed to trigger a certain builder. 36 type unauthorizedIncludedTryjob struct { 37 Users []string 38 Builder string 39 } 40 41 func (uit *unauthorizedIncludedTryjob) Reason() string { 42 switch len(uit.Users) { 43 case 0: 44 panic(fmt.Errorf("impossible, at least one unauthorized user is needed in this failure")) 45 case 1: 46 return fmt.Sprintf("user %s is not allowed to trigger %q", uit.Users[0], uit.Builder) 47 default: 48 return fmt.Sprintf("the following users are not allowed to trigger %q:\n - %s", uit.Builder, strings.Join(uit.Users, "\n - ")) 49 } 50 } 51 52 // buildersNotDefined represents a computation failure where builders explicitly 53 // included in the Run are not known to CV. 54 type buildersNotDefined struct { 55 Builders []string 56 } 57 58 func (bnd *buildersNotDefined) Reason() string { 59 switch len(bnd.Builders) { 60 case 0: 61 panic(fmt.Errorf("impossible: at least one undefined builder is needed in this failure")) 62 case 1: 63 return fmt.Sprintf("builder %q is included but not defined in the LUCI project", bnd.Builders[0]) 64 default: 65 return fmt.Sprintf("the following builders are included but not defined in the LUCI project:\n - %s", strings.Join(bnd.Builders, "\n - ")) 66 } 67 } 68 69 // incompatibleTryjobOptions is a computation failure where multiple Tryjob 70 // options have been provided but they are not compatible with each other. 71 type incompatibleTryjobOptions struct { 72 hasIncludedTryjobs bool 73 hasOverriddenTryjobs bool 74 } 75 76 func (ito *incompatibleTryjobOptions) Reason() string { 77 switch { 78 case ito.hasIncludedTryjobs && ito.hasOverriddenTryjobs: 79 return "Both `Cq-Include-Trybots` and `Override-Tryjobs-For-Automation` are specified. Only one is allowed." 80 default: 81 panic(fmt.Errorf("impossible")) 82 } 83 }