{"record":{"id":"d001c446e78d3f46","repo":"dagger/dagger","slug":"failed-to-convert-map-item-q-w-d001c4","errorCode":null,"errorMessage":"failed to convert map item %q: %w","messagePattern":"failed to convert map item %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/sdk/dang/v2/helpers.go","lineNumber":1350,"sourceCode":"\n\tmod, isMod := fieldType.(dang.TypeScope)\n\tif !isMod {\n\t\treturn nil, fmt.Errorf(\"expected module type, got %T\", fieldType)\n\t}\n\n\tmodVal := dang.NewObject(mod)\n\tfor name, val := range vals {\n\t\texpectedT, found := mod.SchemeOf(name)\n\t\tif !found {\n\t\t\treturn nil, fmt.Errorf(\"module %q does not have a scheme for %q\", mod.Name(), name)\n\t\t}\n\t\tt, isMono := expectedT.Type()\n\t\tif !isMono {\n\t\t\treturn nil, fmt.Errorf(\"expected monomorphic type, got %T\", t)\n\t\t}\n\t\tdangVal, err := c.convert(ctx, val, t)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to convert map item %q: %w\", name, err)\n\t\t}\n\t\tmodVal.Bind(name, dangVal, dang.PrivateVisibility)\n\t}\n\n\tif err := evaluateDangClassBody(ctx, c.env, mod, modVal); err != nil {\n\t\treturn nil, err\n\t}\n\treturn modVal, nil\n}\n\nfunc evaluateDangClassBody(ctx context.Context, env dang.ValueScope, mod dang.TypeScope, modVal *dang.Object) error {\n\tif mod.Name() == \"\" {\n\t\treturn nil\n\t}\n\n\tconstructor, found, err := env.Lookup(ctx, mod.Name())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"lookup constructor %s: %w\", mod.Name(), err)","sourceCodeStart":1332,"sourceCodeEnd":1368,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/sdk/dang/v2/helpers.go#L1332-L1368","documentation":"After resolving a module field's type, convertObject calls c.convert to turn the supplied value into a dang value of that type; any failure is wrapped as 'failed to convert map item %q' with the field name. This tells the developer exactly which module field's value was incompatible with its declared type.","triggerScenarios":"Assigning a value of the wrong type to a module field during map-to-module conversion — e.g. a string where a Directory is expected, an unconvertible object, or a nested conversion failure inside a composite value.","commonSituations":"Passing raw Go/dagql values where dang typed values are required; typos yielding wrong-typed literals; API changes where a field's type changed (e.g. Directory to String) but call sites were not updated.","solutions":["Read the wrapped %w cause to see why the value didn't match field type","Supply a value matching the field's declared type (convert it first if needed)","Update call sites after any module field type change"],"exampleFix":"// before\nconvert(ctx, {src: \"./app\"}, modType) // src expects Directory\n// after\nconvert(ctx, {src: dagql.NewDirectory(\"./app\")}, modType)","handlingStrategy":"validation","validationCode":"// Ensure each value matches the field's declared type before conversion\nfunc validateModuleValues(ctx context.Context, c *converter, mod *dang.Module, vals map[string]any) error {\n\tfor name, val := range vals {\n\t\tscheme, found := mod.SchemeOf(name)\n\t\tif !found { continue }\n\t\tt, ok := scheme.Type()\n\t\tif !ok { continue }\n\t\tif _, err := c.convert(ctx, val, t); err != nil {\n\t\t\treturn fmt.Errorf(\"field %q: %w\", name, err)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"obj, err := convertObject(ctx, c, mod, vals)\nif err != nil {\n\tvar itemErr string\n\tif m := mapItemRe.FindStringSubmatch(err.Error()); m != nil {\n\t\titemErr = m[1] // offending field name\n\t}\n\treturn fmt.Errorf(\"module %s: %w (field %s)\", mod.Name(), err, itemErr)\n}","preventionTips":["Supply values matching each field's declared type","Convert Go/dagql values to dang values before assignment","Update call sites whenever a module field's type changes"],"tags":["dang","module","conversion","type-mismatch"],"backgroundTag":"value-conversion-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"}