siyuan-note/siyuan · error
invalid cloud login code
Error message
invalid cloud login code
What it means
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.
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
Defensive patterns
Strategy: try-catch
Validate before calling
function looksLikeCloudLoginResponse(body: unknown): body is { code: number; msg: string; token?: string } {
return typeof body === 'object' && body !== null && typeof (body as any).code === 'number';
} Type guard
function hasNumericCode(v: unknown): v is { code: number } { return typeof v === 'object' && v !== null && typeof (v as any).code === 'number'; } Try / catch
try { const resp = await cloudLogin(user, pass); } catch (e) { if (String(e).includes('invalid cloud login code')) { inspectRawResponse(); handleCloudServiceOutage(); } } Prevention
- 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
When it happens
Trigger: Unmarshalling a cloud login response whose JSON lacks 'code', has code:null, or contains a non-numeric code value (string, object).
Common situations: 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.
Related errors
- invalid cloud login message
- block ID must be text
- block operation result must be text, block IDs or null
- invalid cloud login token
- invalid OCR metadata
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/ec8067040797f70a.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/apicontract/setting_cloud.go:43
}
var err error
if fields["code"], err = json.Marshal(d.Code); err != nil {
return nil, err
}
if fields["msg"], err = json.Marshal(d.Msg); err != nil {
return nil, err
}
return json.Marshal(fields)
}
func (d *CloudLogin2faData) UnmarshalJSON(raw []byte) error {
var fields map[string]json.RawMessage
if err := json.Unmarshal(raw, &fields); err != nil {
return err
}
code, msg := fields["code"], fields["msg"]
if len(code) == 0 || bytes.Equal(code, []byte("null")) || json.Unmarshal(code, &d.Code) != nil {
return errors.New("invalid cloud login code")
}
if len(msg) == 0 || bytes.Equal(msg, []byte("null")) || json.Unmarshal(msg, &d.Msg) != nil {
return errors.New("invalid cloud login message")
}
if d.Code == 0 {
var token string
if json.Unmarshal(fields["token"], &token) != nil || token == "" {
return errors.New("invalid cloud login token")
}
}
d.Extra = make(map[string]JSONValue, len(fields)-2)
for key, raw := range fields {
if key == "code" || key == "msg" {
continue
}
value, err := EncodedJSONValue(raw)
if err != nil {
return errView on GitHub (pinned to 9f775e8a12)