{"record":{"id":"ec8067040797f70a","repo":"siyuan-note/siyuan","slug":"invalid-cloud-login-code","errorCode":null,"errorMessage":"invalid cloud login code","messagePattern":"invalid cloud login code","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/apicontract/setting_cloud.go","lineNumber":43,"sourceCode":"\t}\n\tvar err error\n\tif fields[\"code\"], err = json.Marshal(d.Code); err != nil {\n\t\treturn nil, err\n\t}\n\tif fields[\"msg\"], err = json.Marshal(d.Msg); err != nil {\n\t\treturn nil, err\n\t}\n\treturn json.Marshal(fields)\n}\n\nfunc (d *CloudLogin2faData) UnmarshalJSON(raw []byte) error {\n\tvar fields map[string]json.RawMessage\n\tif err := json.Unmarshal(raw, &fields); err != nil {\n\t\treturn err\n\t}\n\tcode, msg := fields[\"code\"], fields[\"msg\"]\n\tif len(code) == 0 || bytes.Equal(code, []byte(\"null\")) || json.Unmarshal(code, &d.Code) != nil {\n\t\treturn errors.New(\"invalid cloud login code\")\n\t}\n\tif len(msg) == 0 || bytes.Equal(msg, []byte(\"null\")) || json.Unmarshal(msg, &d.Msg) != nil {\n\t\treturn errors.New(\"invalid cloud login message\")\n\t}\n\tif d.Code == 0 {\n\t\tvar token string\n\t\tif json.Unmarshal(fields[\"token\"], &token) != nil || token == \"\" {\n\t\t\treturn errors.New(\"invalid cloud login token\")\n\t\t}\n\t}\n\td.Extra = make(map[string]JSONValue, len(fields)-2)\n\tfor key, raw := range fields {\n\t\tif key == \"code\" || key == \"msg\" {\n\t\t\tcontinue\n\t\t}\n\t\tvalue, err := EncodedJSONValue(raw)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/apicontract/setting_cloud.go#L25-L61","documentation":"This custom UnmarshalJSON parses the cloud login response payload, requiring a 'code' field that is present, non-null, and decodes into the expected integer type. If any of these checks fail it returns 'invalid cloud login code', rejecting the whole payload.","triggerScenarios":"Unmarshalling a cloud login response whose JSON lacks 'code', has code:null, or contains a non-numeric code value (string, object).","commonSituations":"Cloud service returning an HTML error page or proxy error instead of the expected JSON, an API change in the cloud login response, or a network middleware injecting its own JSON error body.","solutions":["Inspect the raw response body to see what was actually returned","Retry the cloud login; the service may have returned a transient error page","Verify the cloud service endpoint/protocol version matches the client","Confirm the response Content-Type is application/json with code as a number"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function looksLikeCloudLoginResponse(body: unknown): body is { code: number; msg: string; token?: string } {\n  return typeof body === 'object' && body !== null && typeof (body as any).code === 'number';\n}","typeGuard":"function hasNumericCode(v: unknown): v is { code: number } { return typeof v === 'object' && v !== null && typeof (v as any).code === 'number'; }","tryCatchPattern":"try { const resp = await cloudLogin(user, pass); } catch (e) { if (String(e).includes('invalid cloud login code')) { inspectRawResponse(); handleCloudServiceOutage(); } }","preventionTips":["Capture and log the raw HTTP body on login failures","Check response Content-Type is application/json before parsing","Handle gateway/proxy error pages (HTML) explicitly","Pin/verify cloud API protocol versions"],"tags":["json","unmarshal","cloud","login"],"backgroundTag":"unexpected-response-shape","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}