{"record":{"id":"e2eead86a7fedac2","repo":"dagger/dagger","slug":"failed-to-reload-context-after-setting-source-subp","errorCode":null,"errorMessage":"failed to reload context after setting source subpath: %w","messagePattern":"failed to reload context after setting source subpath: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/schema/modulesource.go","lineNumber":1396,"sourceCode":"\t}\n\tsrc.SDK.Source = args.Source\n\n\t// Default source subpath to source root when an SDK is set but no explicit\n\t// source path was configured (e.g. during module init before dagger.json exists).\n\t// This mirrors the logic in initFromModConfig for the sdkSource != \"\" && modCfg.Source == \"\" case.\n\tif src.SourceSubpath == \"\" {\n\t\tsrc.SourceSubpath = src.SourceRootSubpath\n\n\t\t// Reload the context directory now that SourceSubpath is set, so that\n\t\t// the source files are included (e.g. an existing main.go). The initial\n\t\t// load may have used empty SourceSubpath which matches no files.\n\t\terr := s.loadModuleSourceContext(ctx, src)\n\t\tswitch {\n\t\tcase err == nil:\n\t\tcase codes.NotFound == status.Code(err) && src.Kind == core.ModuleSourceKindLocal:\n\t\t\t// tolerate not found during init when context dir doesn't exist yet\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"failed to reload context after setting source subpath: %w\", err)\n\t\t}\n\t}\n\n\t// reload the sdk implementation too\n\tquery, err := core.CurrentQuery(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tsrc.SDKImpl, err = sdk.NewLoader().SDKForModule(ctx, query, src.SDK, src)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load sdk for module source: %w\", err)\n\t}\n\n\t// New SDK means new exposed functions and types. Different .env entries might match.\n\tif err := src.LoadUserDefaults(ctx); err != nil {\n\t\treturn nil, fmt.Errorf(\"load user defaults: %w\", err)\n\t}\n\treturn src, nil","sourceCodeStart":1378,"sourceCodeEnd":1414,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/schema/modulesource.go#L1378-L1414","documentation":"ModuleSource.withSDK changes the module's SDK, which can alter the source subpath; Dagger reloads the context and tolerates only NotFound during init. Any other reload failure is wrapped with 'failed to reload context after setting source subpath'. This indicates the context could not be re-read after the SDK-driven subpath change, typically a filesystem or git problem, not the SDK choice itself.","triggerScenarios":"ModuleSource.withSDK where loading the module context after the SDK default subpath change fails with an unexpected (non-NotFound) error.","commonSituations":"SDK expects a subpath directory that is unreadable; context dir is a broken symlink; git checkout state inconsistent; running inside a container without the mounted context.","solutions":["Confirm the SDK's expected source subpath directory exists and is readable in your module.","Fix broken symlinks or mount points in the context directory.","If using git sources, run git status/checkout to restore a clean state.","Check the wrapped inner error for the precise reload failure."],"exampleFix":"// before: python module context without expected subdir structure\nwithSDK(\"python\") // reload fails\n// after: ensure module layout matches SDK defaults\ncd my-mod && mkdir -p src && dagger mod use . --sdk python","handlingStrategy":"validation","validationCode":"import os\nfor sub in ['src', expected_sdk_subpath]:\n    p = os.path.join(module_root, sub)\n    if not os.path.isdir(p):\n        print(f\"warning: SDK-expected directory missing: {p}\")","typeGuard":null,"tryCatchPattern":"try {\n  await mod.withSDK('python')\n} catch (e) {\n  if (String(e).includes('failed to reload context after setting source subpath')) {\n    console.error('Context unreadable after SDK subpath change:', e.cause ?? e)\n  }\n  throw e\n}","preventionTips":["Match the SDK's expected module layout (e.g. src/ for python) before switching SDKs.","Fix broken symlinks/mounts in the context tree.","Keep git working trees clean when using git module sources.","Ensure the context is mounted when running inside containers."],"tags":["dagger","module-source","sdk","context"],"backgroundTag":"module-context-reload-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}