{"record":{"id":"057615931b9cff60","repo":"dagger/dagger","slug":"marshal-introspection-schema-for-self-call-merge","errorCode":null,"errorMessage":"marshal introspection schema for self-call merge: %w","messagePattern":"marshal introspection schema for self-call merge: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/codegen/generator/go/generate_module.go","lineNumber":154,"sourceCode":"\t\tif slices.Contains(schema.DependencyNames(), moduleName) {\n\t\t\treturn nil, fmt.Errorf(\n\t\t\t\t\"a dependency is installed under the module's own name %q; \"+\n\t\t\t\t\t\"self-calls need distinct names — reinstall the dependency under \"+\n\t\t\t\t\t\"another name (dagger install --name)\", moduleName)\n\t\t}\n\t\temitter := templates.NewModuleIntrospectionEmitter(ctx, schema, schemaVersion, g.Config, pkg, fset)\n\t\tmoduleTypesJSON, err := emitter.ModuleIntrospectionJSON(moduleName)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"emit module types for self-call merge: %w\", err)\n\t\t}\n\t\t// The engine's codegen path always passes --introspection-json-path,\n\t\t// but generate-module can also run against live introspection; in that\n\t\t// case rebuild the JSON the schema tool needs from the schema in hand.\n\t\tdepsJSON := g.Config.IntrospectionJSON\n\t\tif depsJSON == \"\" {\n\t\t\tdata, err := json.Marshal(introspection.Response{Schema: schema, SchemaVersion: schemaVersion})\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"marshal introspection schema for self-call merge: %w\", err)\n\t\t\t}\n\t\t\tdepsJSON = string(data)\n\t\t}\n\t\tmerged, err := g.Config.Dag.\n\t\t\tSchema(dagger.JSON(depsJSON)).\n\t\t\tMerge(dagger.JSON(moduleTypesJSON), moduleName).\n\t\t\tContents(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"merge module types into schema: %w\", err)\n\t\t}\n\t\tvar resp introspection.Response\n\t\tif err := json.Unmarshal([]byte(merged), &resp); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unmarshal merged introspection JSON: %w\", err)\n\t\t}\n\t\tschema = resp.Schema\n\t\tgenerator.SetSchemaParents(schema)\n\t\tgenerator.SetSchema(schema)\n\t}","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/cmd/codegen/generator/go/generate_module.go#L136-L172","documentation":"When no IntrospectionJSON was provided by the engine (generate-module against live introspection), the schema in hand is marshaled to the introspection.Response JSON the schema tool expects; a json.Marshal failure of that struct is wrapped here. This is a defensive wrap — json.Marshal on these structs essentially only fails on unsupported types.","triggerScenarios":"g.Config.IntrospectionJSON == \"\" and json.Marshal(introspection.Response{Schema: schema, SchemaVersion: schemaVersion}) fails — requires an unmarshalable value inside the schema (custom MarshalJSON returning invalid data, channel/func field).","commonSituations":"Running the generate-module path with live introspection on a schema/version combination where introspection.Response or a schema field gained a non-JSON-serializable member (SDK/library version mismatch).","solutions":["Upgrade or align dagger.io/dagger SDK and CLI versions so introspection.Response marshals correctly","Pass --introspection-json-path (engine codegen path) so Config.IntrospectionJSON is set and marshal is skipped","Inspect the wrapped json error's field name and patch/upgrade the offending schema type"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// prefer the engine path so IntrospectionJSON is provided:\n// run codegen through the CLI with --introspection-json-path instead of live introspection\nif introspectionJSONPath == \"\" {\n    log.Println(\"no introspection JSON provided; schema will be re-marshaled (upgrade SDK if this fails)\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := g.GenerateModule(ctx, schema, schemaVersion); err != nil {\n    if strings.Contains(err.Error(), \"marshal introspection schema\") {\n        log.Fatalf(\"introspection.Response unmarshalable — align SDK/CLI versions: %v\", err)\n    }\n    return err\n}","preventionTips":["Use the engine codegen path (--introspection-json-path) rather than live introspection when possible","Keep dagger.io/dagger SDK and CLI versions matching"],"tags":["go","json","introspection","version-mismatch"],"backgroundTag":"json-marshal-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"}