SDKForModule loads an SDK module based on the given SDK configuration. If it's a builtin SDK, it will load it from the engine container. Otherwise, it will load it from the given source either from a URL or from a local path.
( ctx context.Context, query *core.Query, sdk *core.SDKConfig, parentSrc *core.ModuleSource, )
| 39 | // Otherwise, it will load it from the given source either from a URL |
| 40 | // or from a local path. |
| 41 | func (l *Loader) SDKForModule( |
| 42 | ctx context.Context, |
| 43 | query *core.Query, |
| 44 | sdk *core.SDKConfig, |
| 45 | parentSrc *core.ModuleSource, |
| 46 | ) (_ core.SDK, rerr error) { |
| 47 | if sdk == nil { |
| 48 | return nil, errMissingSDKRef |
| 49 | } |
| 50 | |
| 51 | ctx, span := core.Tracer(ctx).Start(ctx, fmt.Sprintf("load SDK: %s", sdk.Source)) |
| 52 | defer telemetry.EndWithCause(span, &rerr) |
| 53 | |
| 54 | builtinSDK, builtinErr := l.namedSDK(ctx, query, sdk) |
| 55 | if builtinErr == nil { |
| 56 | return builtinSDK, nil |
| 57 | } else if !errors.Is(builtinErr, errUnknownBuiltinSDK) { |
| 58 | return nil, builtinErr |
| 59 | } |
| 60 | |
| 61 | extSDK, extErr := l.externalSDKForModule(ctx, query, sdk, parentSrc) |
| 62 | if extErr == nil { |
| 63 | return extSDK, nil |
| 64 | } |
| 65 | |
| 66 | stdio := telemetry.SpanStdio(ctx, "dagger.io/core/sdk") |
| 67 | fmt.Fprintf(stdio.Stderr, "Could not load SDK %q.\n", sdk.Source) |
| 68 | fmt.Fprintln(stdio.Stderr) |
| 69 | fmt.Fprintln(stdio.Stderr, "Errors:") |
| 70 | fmt.Fprintln(stdio.Stderr, "-", builtinErr) |
| 71 | fmt.Fprintln(stdio.Stderr, "-", extErr) |
| 72 | fmt.Fprintln(stdio.Stderr) |
| 73 | fmt.Fprintln(stdio.Stderr, "The available SDKs are:") |
| 74 | for _, sdk := range validInbuiltSDKs { |
| 75 | fmt.Fprintln(stdio.Stderr, "-", sdk) |
| 76 | } |
| 77 | fmt.Fprintln(stdio.Stderr, "- any git module ref, e.g. github.com/dagger/dagger/sdk/elixir@main") |
| 78 | fmt.Fprintln(stdio.Stderr, "- any local module path, e.g. ./my-sdk") |
| 79 | |
| 80 | return nil, fmt.Errorf("invalid SDK: %q", sdk.Source) |
| 81 | } |
| 82 | |
| 83 | // Load an SDK module from an external source (not builtin to the engine). |
| 84 | // |
no test coverage detected