MCPcopy Create free account
hub / github.com/goadesign/goa / validateErrors

Method validateErrors

expr/method.go:242–271  ·  view source on GitHub ↗

validateErrors validates the method errors.

()

Source from the content-addressed store, hash-verified

240
241// validateErrors validates the method errors.
242func (m *MethodExpr) validateErrors() *eval.ValidationErrors {
243 verr := new(eval.ValidationErrors)
244 for i, e := range m.Errors {
245 if err := e.Validate(); err != nil {
246 var verrs *eval.ValidationErrors
247 if errors.As(err, &verrs) {
248 verr.Merge(verrs)
249 }
250 }
251 for j, e2 := range m.Errors {
252 // If an object type is used to define more than one errors validate the
253 // presence of struct:error:name meta in the object type.
254 if i != j && e.Type == e2.Type && IsObject(e.Type) {
255 var found bool
256 walkAttribute(e.AttributeExpr, func(_ string, att *AttributeExpr) error { // nolint: errcheck
257 if _, ok := att.Meta["struct:error:name"]; ok {
258 found = true
259 return fmt.Errorf("struct:error:name found: stop iteration")
260 }
261 return nil
262 })
263 if !found {
264 verr.Add(e, "type %q is used to define multiple errors and must identify the attribute containing the error name with ErrorName", e.Type.Name())
265 break
266 }
267 }
268 }
269 }
270 return verr
271}
272
273// validateInterceptors validates the method interceptors.
274func (m *MethodExpr) validateInterceptors() *eval.ValidationErrors {

Callers 1

ValidateMethod · 0.95

Calls 6

IsObjectFunction · 0.85
walkAttributeFunction · 0.85
AddMethod · 0.80
ValidateMethod · 0.65
NameMethod · 0.65
MergeMethod · 0.45

Tested by

no test coverage detected