{"record":{"id":"f6af0f0bd59a1536","repo":"dagger/dagger","slug":"unexpected-context-type-in-inline-field-s","errorCode":null,"errorMessage":"unexpected context type in inline field %s","messagePattern":"unexpected context type in inline field (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/codegen/generator/go/templates/module_funcs.go","lineNumber":376,"sourceCode":"\t\tif ok {\n\t\t\tstype, ok := asInlineStructAst(fnDecl.Type.Params.List[i].Type)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"expected struct type for %s\", param.Name())\n\t\t\t}\n\n\t\t\tparent := &paramSpec{\n\t\t\t\tname:      params.At(i).Name(),\n\t\t\t\tparamType: param.Type(),\n\t\t\t}\n\n\t\t\tparamFields := unpackASTFields(stype.Fields)\n\t\t\tfor f := range paramType.NumFields() {\n\t\t\t\tspec, err := ps.parseParamSpecVar(paramType.Field(f), paramFields[f], paramFields[f].Doc.Text(), paramFields[f].Comment.Text())\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tif spec.isContext {\n\t\t\t\t\treturn nil, fmt.Errorf(\"unexpected context type in inline field %s\", spec.name)\n\t\t\t\t}\n\t\t\t\tspec.parent = parent\n\t\t\t\tspecs = append(specs, spec)\n\t\t\t}\n\t\t\treturn specs, nil\n\t\t}\n\t}\n\n\t// if other parameter passing schemes fail, just treat each remaining arg\n\t// as a top-level param\n\tparamFields := unpackASTFields(fnDecl.Type.Params)\n\tfor ; i < params.Len(); i++ {\n\t\tdocComment, lineComment := ps.commentForFuncField(fnDecl, paramFields, i)\n\t\tspec, err := ps.parseParamSpecVar(params.At(i), paramFields[i], docComment.Text(), lineComment.Text())\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif spec.isContext {","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/cmd/codegen/generator/go/templates/module_funcs.go#L358-L394","documentation":"When a Dagger function takes a single inline-struct argument, each field of that struct becomes its own exposed argument. A field whose type is context.Context cannot be exposed as an argument, so codegen rejects it with this error naming the offending field.","triggerScenarios":"Declaring a context.Context field inside the anonymous struct used as a function's single argument object.","commonSituations":"Copy-pasting a normal function signature's parameters into a struct; misunderstanding that only the top-level function may take ctx.","solutions":["Remove the context.Context field from the inline struct","Keep ctx as the first parameter of the function itself, not inside the struct","Use a different type for the field if state was intended"],"exampleFix":"// before\nfunc (m *Mod) Foo(ctx context.Context, args struct {\n  Ctx context.Context\n  Name string\n}) error\n\n// after\nfunc (m *Mod) Foo(ctx context.Context, args struct {\n  Name string\n}) error","handlingStrategy":"validation","validationCode":"// ensure no context.Context fields inside inline-struct args\nfor _, f := range reflect.TypeOf(args).FieldList() /* compile-time: just don't declare it */ {}","typeGuard":null,"tryCatchPattern":"if err := runCodegen(); err != nil {\n    if strings.Contains(err.Error(), \"unexpected context type in inline field\") {\n        // remove the ctx field from the struct\n    }\n}","preventionTips":["Only the function's first parameter may be context.Context","Never add ctx fields inside argument structs","Lint module functions for ctx placement"],"tags":["codegen","go","dagger-module","inline-struct"],"backgroundTag":"context-in-struct-field","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"}