{"record":{"id":"e26c657b3eab9522","repo":"dagger/dagger","slug":"unmarshal-module-config-w","errorCode":null,"errorMessage":"unmarshal module config: %w","messagePattern":"unmarshal module config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/modules/config.go","lineNumber":282,"sourceCode":"\t*sdk = SDK(tmp)\n\treturn nil\n}\n\nfunc (modCfg *ModuleConfig) UnmarshalJSON(data []byte) error {\n\tif modCfg == nil {\n\t\treturn fmt.Errorf(\"cannot unmarshal into nil %T\", modCfg)\n\t}\n\tif len(data) == 0 {\n\t\treturn nil\n\t}\n\n\ttype alias ModuleConfig // lets us use the default json unmashaler\n\tvar tmp struct {\n\t\talias\n\t\tRuntime *SDK `json:\"runtime,omitempty\"`\n\t}\n\tif err := json.Unmarshal(data, &tmp); err != nil {\n\t\treturn fmt.Errorf(\"unmarshal module config: %w\", err)\n\t}\n\tif tmp.Runtime != nil {\n\t\tif tmp.SDK != nil && !reflect.DeepEqual(tmp.SDK, tmp.Runtime) {\n\t\t\treturn fmt.Errorf(\"module config cannot set both sdk and runtime\")\n\t\t}\n\t\ttmp.SDK = tmp.Runtime\n\t}\n\n\tloaded := ModuleConfig(tmp.alias)\n\tnormalizeLoadedModuleConfig(&loaded)\n\t*modCfg = loaded\n\treturn nil\n}\n\nfunc normalizeLoadedModuleConfig(modCfg *ModuleConfig) {\n\tif modCfg == nil {\n\t\treturn\n\t}","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/modules/config.go#L264-L300","documentation":"ModuleConfig.UnmarshalJSON decodes into an alias of ModuleConfig plus an extra Runtime *SDK field, because current configs may spell the sdk key as \"runtime\". If the underlying json.Unmarshal of the whole config fails — any field anywhere in the config has a wrong JSON type or the JSON is malformed — it is wrapped as \"unmarshal module config\" so the config-level decode failure is clearly attributed.","triggerScenarios":"Loading a dagger.json where any ModuleConfig field has a mismatched JSON type (e.g. include/exclude as a string instead of an array, dependencies as an object instead of a list) or the file is otherwise invalid JSON; decoding via UnmarshalModuleConfig or the ModuleConfigWithUserFields unmarshaler which delegates here.","commonSituations":"Hand-edited configs with wrong types; config generated by an older or newer dagger version whose schema drifted; truncated or corrupted dagger.json files.","solutions":["Run `jq . dagger.json` (or a JSON linter) to locate the malformed portion of the config","Compare the failing field's type against the ModuleConfig schema in core/modules/config.go and fix the JSON type (arrays, objects, strings)","Regenerate the config with a matching dagger CLI version (`dagger mod sync`) to normalize the schema","If the file was written by an older dagger version, load it once with that version and let the CLI migrate it"],"exampleFix":"// dagger.json before\n\"include\": \"*.go\"        // should be an array\n// after\n\"include\": [\"*.go\"]","handlingStrategy":"validation","validationCode":"// spot-check core field types before loading\nvar probe struct {\n\tInclude      []string          `json:\"include\"`\n\tExclude      []string          `json:\"exclude\"`\n\tDependencies []json.RawMessage `json:\"dependencies\"`\n\tSDK          json.RawMessage   `json:\"sdk\"`\n\tRuntime      json.RawMessage   `json:\"runtime\"`\n}\nif err := json.Unmarshal(raw, &probe); err != nil {\n\treturn fmt.Errorf(\"fix field types in dagger.json: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"var cfg modules.ModuleConfig\nif err := json.Unmarshal(raw, &cfg); err != nil {\n\treturn fmt.Errorf(\"invalid dagger.json: %w\", err)\n}","preventionTips":["Lint dagger.json with `jq .` after every manual edit","Match each field's JSON type to the ModuleConfig schema (arrays for include/exclude, list for dependencies)","Regenerate the config via the CLI when unsure of the current schema"],"tags":["dagger","module-config","json-unmarshal","schema-validation"],"backgroundTag":"schema-validation-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"}