MCPcopy Index your code
hub / github.com/dagger/dagger / Patch

Method Patch

core/module.go:1835–1999  ·  view source on GitHub ↗

Patch is called after all types have been loaded - here we can update any definitions as required, and attempt to resolve references. nolint:gocyclo // intrinsically long state machine; refactoring would hurt clarity

(ctx context.Context)

Source from the content-addressed store, hash-verified

1833//
1834//nolint:gocyclo // intrinsically long state machine; refactoring would hurt clarity
1835func (mod *Module) Patch(ctx context.Context) error {
1836 dag, err := CurrentDagqlServer(ctx)
1837 if err != nil {
1838 return fmt.Errorf("current dagql server: %w", err)
1839 }
1840
1841 patchFunctionEnumDefaults := func(fn dagql.ObjectResult[*Function]) (dagql.ObjectResult[*Function], error) {
1842 updated := fn
1843 for _, arg := range fn.Self().Args {
1844 argSelf := arg.Self()
1845 if argSelf.DefaultValue == nil {
1846 continue
1847 }
1848 if argSelf.TypeDef.Self().Kind != TypeDefKindEnum {
1849 continue
1850 }
1851 var enumTypeDef *EnumTypeDef
1852 for _, enum := range mod.EnumDefs {
1853 if enum.Self().AsEnum.Value.Self().Name == argSelf.TypeDef.Self().AsEnum.Value.Self().Name {
1854 enumTypeDef = enum.Self().AsEnum.Value.Self()
1855 break
1856 }
1857 }
1858 if enumTypeDef == nil {
1859 continue
1860 }
1861
1862 var val string
1863 dec := json.NewDecoder(bytes.NewReader(argSelf.DefaultValue.Bytes()))
1864 dec.UseNumber()
1865 if err := dec.Decode(&val); err != nil {
1866 return updated, fmt.Errorf("failed to decode default value for arg %q: %w", argSelf.Name, err)
1867 }
1868
1869 found := false
1870 for _, member := range enumTypeDef.Members {
1871 memberSelf := member.Self()
1872 if val == memberSelf.OriginalName {
1873 val = memberSelf.Name
1874 found = true
1875 break
1876 }
1877 }
1878 if !found {
1879 return updated, fmt.Errorf("enum name %q not found", val)
1880 }
1881
1882 res, err := json.Marshal(val)
1883 if err != nil {
1884 return updated, err
1885 }
1886 var updatedArg dagql.ObjectResult[*FunctionArg]
1887 if err := dag.Select(ctx, arg, &updatedArg, dagql.Selector{
1888 Field: "__withDefaultValue",
1889 Args: []dagql.NamedInput{{Name: "defaultValue", Value: JSON(res)}},
1890 }); err != nil {
1891 return updated, fmt.Errorf("patch enum default arg %q: %w", argSelf.Name, err)
1892 }

Callers 1

runModuleDefInSDKMethod · 0.80

Calls 9

sameAttachedResultFunction · 0.85
ResultIDInputFunction · 0.85
SelfMethod · 0.80
BytesMethod · 0.80
CurrentDagqlServerFunction · 0.70
JSONTypeAlias · 0.70
MarshalMethod · 0.65
SelectMethod · 0.65
DecodeMethod · 0.45

Tested by

no test coverage detected