{"record":{"id":"b960678981863209","repo":"dagger/dagger","slug":"marshal-arg-q-w","errorCode":null,"errorMessage":"marshal arg %q: %w","messagePattern":"marshal arg %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/modfunc.go","lineNumber":173,"sourceCode":"\t\t}\n\n\t\tname := arg.metadata.OriginalName\n\n\t\tconverted, err := arg.modType.ConvertToSDKInput(ctx, input.Value)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"convert arg %q: %w\", input.Name, err)\n\t\t}\n\n\t\tif len(arg.metadata.Ignore) > 0 && !arg.metadata.isContextual() { // contextual args already have ignore applied\n\t\t\tconverted, err = fn.applyIgnoreOnDir(ctx, opts.Server, arg.metadata, converted)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"apply ignore pattern on arg %q: %w\", input.Name, err)\n\t\t\t}\n\t\t}\n\n\t\tencoded, err := json.Marshal(converted)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"marshal arg %q: %w\", input.Name, err)\n\t\t}\n\n\t\tcallInputs[i] = &FunctionCallArgValue{\n\t\t\tName:  name,\n\t\t\tValue: encoded,\n\t\t}\n\n\t\thasArg[name] = true\n\t}\n\n\t// Load default value\n\tfor _, argRes := range fn.metadata.Args {\n\t\targ := argRes.Self()\n\t\tname := arg.OriginalName\n\t\tif hasArg[name] {\n\t\t\tcontinue\n\t\t}\n\t\tuserDefault, hasUserDefault, err := fn.UserDefault(ctx, arg.Name)","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/modfunc.go#L155-L191","documentation":"Raised in setCallInputs when json.Marshal fails on the converted argument value just before building the FunctionCallArgValue. In Go, json.Marshal fails mainly on unsupported types (channels, funcs, cycles), so this indicates the SDK conversion produced a value that is not JSON-encodable.","triggerScenarios":"An argument value, after ConvertToSDKInput (and optional ignore application), contains a Go type the encoding/json package cannot serialize: cyclic structures, channels, function values, or a custom MarshalJSON that errors.","commonSituations":"Custom types in a module SDK lacking JSON marshaling support; a converter returning a cyclic or invalid structure; buggy custom SDK input conversion for a newly added argument type.","solutions":["Inspect the wrapped marshal error to identify the unsupported type","Make sure the argument's type is one of the supported module function input types (primitives, IDs, lists, JSON-serializable structs)","Fix or regenerate the SDK so the converted input is a plain JSON-encodable value","If a custom type was added, implement MarshalJSON or map it to a supported representation"],"exampleFix":"// before\ntype Opts struct { CB func() } // not JSON-encodable\n// after\ntype Opts struct { Name string `json:\"name\"` }","handlingStrategy":"validation","validationCode":"// Ensure the value survives a JSON round-trip before passing it\ntry { JSON.parse(JSON.stringify(value)) } catch { throw new Error('arg value is not JSON-serializable') }","typeGuard":"function isJsonSerializable(v: unknown): boolean {\n  try { JSON.stringify(v); return true } catch { return false }\n}","tryCatchPattern":"try {\n  await mod.run(opts)\n} catch (e) {\n  if (String(e).includes('marshal arg')) console.error('argument contained a non-serializable value', e)\n  throw e\n}","preventionTips":["Only pass primitives, lists, JSON objects, and Dagger core objects as args","Avoid functions, callbacks, or class instances with circular refs in arg structs","Add json tags to custom struct types in Go module SDKs"],"tags":["dagger","json","serialization"],"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"}