Validate checks that the error name is found in the result meta for custom error types.
()
| 104 | // Validate checks that the error name is found in the result meta for |
| 105 | // custom error types. |
| 106 | func (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. |
nothing calls this directly
no test coverage detected