(ctx context.Context)
| 136 | } |
| 137 | } |
| 138 | func dispatch(ctx context.Context) (rerr error) { |
| 139 | ctx = telemetry.InitEmbedded(ctx, resource.NewWithAttributes( |
| 140 | semconv.SchemaURL, |
| 141 | semconv.ServiceNameKey.String("dagger-go-sdk"), |
| 142 | // TODO version? |
| 143 | )) |
| 144 | defer telemetry.Close() |
| 145 | |
| 146 | // A lot of the "work" actually happens when we're marshalling the return |
| 147 | // value, which entails getting object IDs, which happens in MarshalJSON, |
| 148 | // which has no ctx argument, so we use this lovely global variable. |
| 149 | setMarshalContext(ctx) |
| 150 | |
| 151 | fnCall := dag.CurrentFunctionCall() |
| 152 | defer func() { |
| 153 | if rerr != nil { |
| 154 | if err := fnCall.ReturnError(ctx, convertError(rerr)); err != nil { |
| 155 | fmt.Println("failed to return error:", err, "\noriginal error:", rerr) |
| 156 | } |
| 157 | } |
| 158 | }() |
| 159 | |
| 160 | parentName, err := fnCall.ParentName(ctx) |
| 161 | if err != nil { |
| 162 | return fmt.Errorf("get parent name: %w", err) |
| 163 | } |
| 164 | fnName, err := fnCall.Name(ctx) |
| 165 | if err != nil { |
| 166 | return fmt.Errorf("get fn name: %w", err) |
| 167 | } |
| 168 | parentJson, err := fnCall.Parent(ctx) |
| 169 | if err != nil { |
| 170 | return fmt.Errorf("get fn parent: %w", err) |
| 171 | } |
| 172 | fnArgs, err := fnCall.InputArgs(ctx) |
| 173 | if err != nil { |
| 174 | return fmt.Errorf("get fn args: %w", err) |
| 175 | } |
| 176 | |
| 177 | inputArgs := map[string][]byte{} |
| 178 | for _, fnArg := range fnArgs { |
| 179 | argName, err := fnArg.Name(ctx) |
| 180 | if err != nil { |
| 181 | return fmt.Errorf("get fn arg name: %w", err) |
| 182 | } |
| 183 | argValue, err := fnArg.Value(ctx) |
| 184 | if err != nil { |
| 185 | return fmt.Errorf("get fn arg value: %w", err) |
| 186 | } |
| 187 | inputArgs[argName] = []byte(argValue) |
| 188 | } |
| 189 | |
| 190 | result, err := invoke(ctx, []byte(parentJson), parentName, fnName, inputArgs) |
| 191 | if err != nil { |
| 192 | return err |
| 193 | } |
| 194 | resultBytes, err := json.Marshal(result) |
| 195 | if err != nil { |
no test coverage detected