{"record":{"id":"fb81f5f3e4f24469","repo":"AlexxIT/go2rtc","slug":"failed-to-marshal-session-request-w","errorCode":null,"errorMessage":"failed to marshal session request: %w","messagePattern":"failed to marshal session request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/ring/api.go","lineNumber":539,"sourceCode":"\t// Make sure we have a valid auth token\n\tif err := c.ensureAuth(); err != nil {\n\t\treturn fmt.Errorf(\"authentication failed while creating session: %w\", err)\n\t}\n\n\tsessionPayload := map[string]interface{}{\n\t\t\"device\": map[string]interface{}{\n\t\t\t\"hardware_id\": c.hardwareID,\n\t\t\t\"metadata\": map[string]interface{}{\n\t\t\t\t\"api_version\":  apiVersion,\n\t\t\t\t\"device_model\": \"ring-client-go\",\n\t\t\t},\n\t\t\t\"os\": \"android\",\n\t\t},\n\t}\n\n\tbody, err := json.Marshal(sessionPayload)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal session request: %w\", err)\n\t}\n\n\treq, err := http.NewRequest(\"POST\", ClientAPI(\"session\"), bytes.NewReader(body))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"Accept\", \"application/json\")\n\treq.Header.Set(\"Authorization\", \"Bearer \"+c.authToken.AccessToken)\n\treq.Header.Set(\"hardware_id\", c.hardwareID)\n\treq.Header.Set(\"User-Agent\", \"android:com.ringapp\")\n\n\tresp, err := c.httpClient.Do(req)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer resp.Body.Close()","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/ring/api.go#L521-L557","documentation":"Returned when json.Marshal fails on the session payload map built for the session creation request. The payload is a map[string]interface{} containing the hardware_id and device metadata, so marshal failures are rare but possible (e.g. values not JSON-serializable).","triggerScenarios":"Calling the session-creation path where the sessionPayload map cannot be serialized by encoding/json (e.g. a non-marshalable value was placed in the metadata map).","commonSituations":"Custom code that modified the payload structure or hardware ID value types; unusual custom client configurations injecting unsupported types.","solutions":["Inspect the wrapped error to identify which value failed to marshal","Ensure hardwareID and all metadata values are JSON-serializable (strings, numbers, bools, maps, slices)","Use standard library JSON-compatible types in the payload"],"exampleFix":"// before\npayload[\"device\"].(map[string]interface{})[\"metadata\"][\"fn\"] = func(){} // unmarshalable\n// after\npayload[\"device\"].(map[string]interface{})[\"metadata\"][\"version\"] = \"1.2.3\"","handlingStrategy":"validation","validationCode":"func isJSONSafe(v map[string]interface{}) bool {\n    b, err := json.Marshal(v)\n    return err == nil && b != nil\n}\n// call before constructing the client payload","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only put JSON-native types (string, number, bool, map, slice) into payload/config maps","Never inject funcs, channels, or custom types into client configuration","Test session creation in CI with your exact configuration"],"tags":["json","serialization","ring"],"backgroundTag":"json-marshal-failed","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}