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

Method buildErrorConvertData

grpc/codegen/service_data.go:1138–1172  ·  view source on GitHub ↗
(ge *expr.GRPCErrorExpr, e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool)

Source from the content-addressed store, hash-verified

1136}
1137
1138func (d *ServicesData) buildErrorConvertData(ge *expr.GRPCErrorExpr, e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *ConvertData {
1139 // No need to build transformation functions for default error or non-object
1140 // types.
1141 if ge.Type == expr.ErrorResult || !expr.IsObject(ge.Type) {
1142 return nil
1143 }
1144 svc := sd.Service
1145 svcCtx := serviceTypeContext(svc.PkgName, svc.Scope)
1146 if svr {
1147 // server side
1148 data := d.buildInitData(ge.AttributeExpr, ge.Response.Message, "er", "message", svcCtx, true, svr, false, sd)
1149 data.Name = fmt.Sprintf("New%s%sError", codegen.Goify(e.Name(), true), codegen.Goify(ge.Name, true))
1150 data.Description = fmt.Sprintf("%s builds the gRPC error response type from the error of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name)
1151 return &ConvertData{
1152 SrcName: svcCtx.Scope.Name(ge.AttributeExpr, svcCtx.Pkg(ge.AttributeExpr), svcCtx.Pointer, svcCtx.UseDefault),
1153 SrcRef: svcCtx.Scope.Ref(ge.AttributeExpr, svcCtx.Pkg(ge.AttributeExpr)),
1154 TgtName: protoBufGoFullTypeName(ge.Response.Message, sd.PkgName, sd.Scope),
1155 TgtRef: protoBufGoFullTypeRef(ge.Response.Message, sd.PkgName, sd.Scope),
1156 Init: data,
1157 }
1158 }
1159
1160 // client side
1161 data := d.buildInitData(ge.Response.Message, ge.AttributeExpr, "message", "er", svcCtx, false, svr, false, sd)
1162 data.Name = fmt.Sprintf("New%s%sError", codegen.Goify(e.Name(), true), codegen.Goify(ge.Name, true))
1163 data.Description = fmt.Sprintf("%s builds the error type of the %q endpoint of the %q service from the gRPC error response type.", data.Name, e.Name(), svc.Name)
1164 return &ConvertData{
1165 SrcName: protoBufGoFullTypeName(ge.Response.Message, sd.PkgName, sd.Scope),
1166 SrcRef: protoBufGoFullTypeRef(ge.Response.Message, sd.PkgName, sd.Scope),
1167 TgtName: svcCtx.Scope.Name(ge.AttributeExpr, svcCtx.Pkg(ge.AttributeExpr), svcCtx.Pointer, svcCtx.UseDefault),
1168 TgtRef: svcCtx.Scope.Ref(ge.AttributeExpr, svcCtx.Pkg(ge.AttributeExpr)),
1169 Init: data,
1170 Validation: addValidation(ge.Response.Message, "errmsg", sd, false),
1171 }
1172}
1173
1174// buildStreamData builds the StreamData for the server and client streams.
1175//

Callers 1

buildErrorsDataMethod · 0.95

Calls 10

buildInitDataMethod · 0.95
IsObjectFunction · 0.92
GoifyFunction · 0.92
serviceTypeContextFunction · 0.85
protoBufGoFullTypeNameFunction · 0.85
protoBufGoFullTypeRefFunction · 0.85
addValidationFunction · 0.85
PkgMethod · 0.80
NameMethod · 0.65
RefMethod · 0.65

Tested by

no test coverage detected