{"record":{"id":"538939704baba35c","repo":"dagger/dagger","slug":"serialize-user-config-w","errorCode":null,"errorMessage":"serialize user config: %w","messagePattern":"serialize user config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/workspace/userconfig.go","lineNumber":273,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\ttree, entryKey, err := userConfigTreeAndEntryKey(existing, workspaceKey)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar value any\n\tif values != nil {\n\t\tvalue = values\n\t} else {\n\t\tvalue = parseValueString(parts, rawValue)\n\t}\n\ttree.SetPath(append([]string{\"workspaces\", entryKey}, parts...), value)\n\n\tout, err := tree.ToTomlString()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"serialize user config: %w\", err)\n\t}\n\treturn []byte(out), nil\n}\n\n// DeleteUserConfigValue removes a config value under\n// [workspaces.<workspaceKey>] in user-level config bytes, pruning any tables\n// the removal leaves empty. It errors when the key is not set for that\n// workspace.\nfunc DeleteUserConfigValue(existing []byte, workspaceKey, key string) ([]byte, error) {\n\tparts, err := userOverlayKeyParts(key)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ttree, entryKey, err := userConfigTreeAndEntryKey(existing, workspaceKey)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/workspace/userconfig.go#L255-L291","documentation":"After writing a value into the TOML tree at [workspaces.<workspaceKey>], WriteUserConfigValue serializes the tree back to TOML with tree.ToTomlString(). This error wraps serialization failure — typically a value type the TOML writer cannot represent (maps with mixed types, unsupported primitives, empty map keys) inserted at the computed path.","triggerScenarios":"WriteUserConfigValue called with a rawValue that parses (via parseValueString) into a TOML-incompatible value, then tree.ToTomlString() fails; also triggered by an entryKey or key path containing segments the TOML writer cannot render as table names.","commonSituations":"Passing JSON-like nested structures as raw values that don't round-trip through TOML; workspace keys containing characters that produce invalid TOML table headers; writing values via scripting with unquoted special characters.","solutions":["Pass a scalar value (string, number, bool) or ensure the raw value parses to a TOML-compatible type","Quote or normalize the workspace entry key so it forms a valid TOML table name","Inspect the wrapped inner error for the offending path/type and adjust the value","If writing structured data, store it as a JSON string in a settings value instead of a nested table"],"exampleFix":"// before\nWriteUserConfigValue(data, key, \"{a: 1}\") // unparseable structure\n// after\nWriteUserConfigValue(data, key, \"30\") // scalar value serializes cleanly","handlingStrategy":"validation","validationCode":"v := parseValueString(parts, raw)\nswitch v.(type) {\ncase string, int64, float64, bool:\ndefault:\n\treturn fmt.Errorf(\"value %v is not TOML-serializable\", raw)\n}","typeGuard":"func tomlSafeValue(v any) bool {\n\tswitch v.(type) { case string, int64, float64, bool: return true }; return false\n}","tryCatchPattern":"out, err := workspace.WriteUserConfigValue(data, key, wsKey, raw)\nif err != nil && strings.Contains(err.Error(), \"serialize user config\") {\n\t// retry with a stringified scalar value\n\tout, err = workspace.WriteUserConfigValue(data, key, wsKey, fmt.Sprintf(\"%v\", raw))\n}","preventionTips":["Write only scalar values through the settings API","Quote workspace keys containing special characters when hand-editing TOML","Round-trip test: parse the output TOML after every programmatic write"],"tags":["go","config","toml","serialization"],"backgroundTag":"config-serialization-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"}