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

Method Validate

expr/service.go:106–128  ·  view source on GitHub ↗

Validate checks that the error name is found in the result meta for custom error types.

()

Source from the content-addressed store, hash-verified

104// Validate checks that the error name is found in the result meta for
105// custom error types.
106func (e *ErrorExpr) Validate() error {
107 verr := new(eval.ValidationErrors)
108 var errField string
109 walkAttribute(e.AttributeExpr, func(name string, att *AttributeExpr) error { // nolint: errcheck
110 if _, ok := att.Meta["struct:error:name"]; ok {
111 if errField != "" {
112 verr.Add(e, "duplicate error names in type %q", e.Type.Name())
113 }
114 errField = name
115 if att.Type != String {
116 verr.Add(e, "error name %q must be a string in type %q", name, e.Type.Name())
117 }
118 if !e.IsRequired(name) {
119 verr.Add(e, "error name %q must be required in type %q", name, e.Type.Name())
120 }
121 }
122 return nil
123 })
124 if len(verr.Errors) > 0 {
125 return verr
126 }
127 return nil
128}
129
130// Finalize makes sure the error type is a user type since it has to generate a
131// Go error.

Callers

nothing calls this directly

Calls 4

walkAttributeFunction · 0.85
AddMethod · 0.80
IsRequiredMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected