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

Method Finalize

expr/service.go:133–160  ·  view source on GitHub ↗

Finalize makes sure the error type is a user type since it has to generate a Go error. Note: this may produce a user type with an attribute that is not an object!

()

Source from the content-addressed store, hash-verified

131// Go error.
132// Note: this may produce a user type with an attribute that is not an object!
133func (e *ErrorExpr) Finalize() {
134 att := e.AttributeExpr
135 switch dt := att.Type.(type) {
136 case UserType:
137 if dt != ErrorResult {
138 // If this type contains an attribute with "struct:error:name" meta
139 // then no need to do anything.
140 if IsObject(dt) {
141 for _, nat := range *AsObject(dt) {
142 if _, ok := nat.Attribute.Meta["struct:error:name"]; ok {
143 return
144 }
145 }
146 }
147
148 // This type does not have an attribute with "struct:error:name" meta.
149 // It means the type is used by at most one error (otherwise validations
150 // would have failed).
151 dt.Attribute().AddMeta("struct:error:name", e.Name)
152 }
153 default:
154 ut := &UserTypeExpr{
155 AttributeExpr: att,
156 TypeName: e.Name,
157 }
158 e.AttributeExpr = &AttributeExpr{Type: ut}
159 }
160}

Callers

nothing calls this directly

Calls 4

IsObjectFunction · 0.85
AsObjectFunction · 0.85
AddMetaMethod · 0.65
AttributeMethod · 0.65

Tested by

no test coverage detected