MCPcopy Create free account
hub / github.com/dagger/dagger / dispatch

Function dispatch

modules/alpine/dagger.gen.go:200–265  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

198 }
199}
200func dispatch(ctx context.Context) (rerr error) {
201 ctx = telemetry.InitEmbedded(ctx, resource.NewWithAttributes(
202 semconv.SchemaURL,
203 semconv.ServiceNameKey.String("dagger-go-sdk"),
204 // TODO version?
205 ))
206 defer telemetry.Close()
207
208 // A lot of the "work" actually happens when we're marshalling the return
209 // value, which entails getting object IDs, which happens in MarshalJSON,
210 // which has no ctx argument, so we use this lovely global variable.
211 setMarshalContext(ctx)
212
213 fnCall := dag.CurrentFunctionCall()
214 defer func() {
215 if rerr != nil {
216 if err := fnCall.ReturnError(ctx, convertError(rerr)); err != nil {
217 fmt.Println("failed to return error:", err, "\noriginal error:", rerr)
218 }
219 }
220 }()
221
222 parentName, err := fnCall.ParentName(ctx)
223 if err != nil {
224 return fmt.Errorf("get parent name: %w", err)
225 }
226 fnName, err := fnCall.Name(ctx)
227 if err != nil {
228 return fmt.Errorf("get fn name: %w", err)
229 }
230 parentJson, err := fnCall.Parent(ctx)
231 if err != nil {
232 return fmt.Errorf("get fn parent: %w", err)
233 }
234 fnArgs, err := fnCall.InputArgs(ctx)
235 if err != nil {
236 return fmt.Errorf("get fn args: %w", err)
237 }
238
239 inputArgs := map[string][]byte{}
240 for _, fnArg := range fnArgs {
241 argName, err := fnArg.Name(ctx)
242 if err != nil {
243 return fmt.Errorf("get fn arg name: %w", err)
244 }
245 argValue, err := fnArg.Value(ctx)
246 if err != nil {
247 return fmt.Errorf("get fn arg value: %w", err)
248 }
249 inputArgs[argName] = []byte(argValue)
250 }
251
252 result, err := invoke(ctx, []byte(parentJson), parentName, fnName, inputArgs)
253 if err != nil {
254 return err
255 }
256 resultBytes, err := json.Marshal(result)
257 if err != nil {

Callers 1

mainFunction · 0.70

Calls 15

setMarshalContextFunction · 0.70
convertErrorFunction · 0.70
invokeFunction · 0.70
StringMethod · 0.65
CloseMethod · 0.65
CurrentFunctionCallMethod · 0.65
NameMethod · 0.65
ValueMethod · 0.65
MarshalMethod · 0.65
ReturnErrorMethod · 0.45
ParentNameMethod · 0.45
ParentMethod · 0.45

Tested by

no test coverage detected