{"record":{"id":"6578f92896637f2e","repo":"dagger/dagger","slug":"decode-sdk-init-args-w","errorCode":null,"errorMessage":"decode sdk init args: %w","messagePattern":"decode sdk init args: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/sdk/module_init.go","lineNumber":167,"sourceCode":"\t\t}\n\t}\n\tslices.Sort(unknown)\n\tif len(unknown) > 0 {\n\t\treturn nil, fmt.Errorf(\"unknown sdk %s arg(s): %v\", fn.Name, unknown)\n\t}\n\n\treturn named, nil\n}\n\nfunc DecodeInitArgs(raw core.JSON) (map[string]any, error) {\n\tif len(raw) == 0 {\n\t\treturn nil, nil\n\t}\n\tvar args map[string]any\n\tdec := json.NewDecoder(bytes.NewReader(raw.Bytes()))\n\tdec.UseNumber()\n\tif err := dec.Decode(&args); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode sdk init args: %w\", err)\n\t}\n\treturn args, nil\n}\n","sourceCodeStart":149,"sourceCodeEnd":171,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/sdk/module_init.go#L149-L171","documentation":"DecodeInitArgs parses the raw JSON blob of SDK init arguments into a map. This error wraps a JSON decode failure: the raw payload is not a JSON object (or is malformed JSON). Dagger uses json.Decoder with UseNumber to preserve numeric fidelity.","triggerScenarios":"Calling DecodeInitArgs (core/sdk/module_init.go:159-170) with a non-empty raw core.JSON that is malformed, or a valid JSON array/string/number rather than an object (decoding into map[string]any fails).","commonSituations":"A caller (e.g. an SDK wrapper) passing user config through without validating it's a JSON object; hand-edited dagger.json or CLI flags producing invalid JSON; encoding bugs in upstream tooling.","solutions":["Validate the JSON string is well-formed with a linter/parser before passing it in.","Ensure the payload is a JSON object ({...}) whose values are all valid JSON scalars/objects.","If config comes from a file, re-serialize it with a JSON encoder instead of string concatenation.","Check the wrapped inner error for the exact byte offset of the syntax error."],"exampleFix":"// before\nraw := core.JSON(`layout=3`)                 // not JSON\n// after\nraw, _ := json.Marshal(map[string]any{\"layout\": 3}) // {\"layout\":3}","handlingStrategy":"validation","validationCode":"var probe map[string]any\nif err := json.Unmarshal(rawConfig, &probe); err != nil {\n    return fmt.Errorf(\"init args must be a JSON object: %w\", err)\n}","typeGuard":"func isJSONObject(raw []byte) bool {\n    var m map[string]any\n    return json.Unmarshal(raw, &m) == nil\n}","tryCatchPattern":"args, err := sdk.DecodeInitArgs(raw)\nif err != nil {\n    if strings.Contains(err.Error(), \"decode sdk init args\") {\n        // treat as invalid config: surface a user-facing validation message\n    }\n    return err\n}","preventionTips":["Always serialize config with a JSON encoder, never string concatenation.","Lint dagger.json and any embedded config before invoking init.","Ensure the payload is an object, not an array or scalar."],"tags":["dagger","json","decoding","validation"],"backgroundTag":"invalid-json","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"}