validateErrors validates the method errors.
()
| 240 | |
| 241 | // validateErrors validates the method errors. |
| 242 | func (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. |
| 274 | func (m *MethodExpr) validateInterceptors() *eval.ValidationErrors { |