{"record":{"id":"b5540280e93c99b9","repo":"siyuan-note/siyuan","slug":"result-msg-string","errorCode":null,"errorMessage":"result[\"msg\"].(string)","messagePattern":"result\\[\"msg\"\\]\\.\\(string\\)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/cloud_service.go","lineNumber":450,"sourceCode":"\t\tSetSuccessResult(&result).\n\t\tSetCookies(&http.Cookie{Name: \"symphony\", Value: Conf.GetUser().UserToken}).\n\t\tSetBody(body).\n\t\tPost(util.GetCloudServer() + \"/apis/siyuan/inbox/removeCloudShorthands\")\n\tif err != nil {\n\t\tlogging.LogErrorf(\"remove cloud shorthands failed: %s\", err)\n\t\terr = ErrFailedToConnectCloudServer\n\t\treturn\n\t}\n\n\tif 401 == resp.StatusCode {\n\t\terr = errors.New(Conf.Language(31))\n\t\treturn\n\t}\n\n\tcode := result[\"code\"].(float64)\n\tif 0 != code {\n\t\tlogging.LogErrorf(\"remove cloud shorthands failed: %s\", result[\"msg\"])\n\t\terr = errors.New(result[\"msg\"].(string))\n\t\treturn\n\t}\n\treturn\n}\n\nfunc GetCloudShorthand(id string) (ret map[string]any, err error) {\n\tresult := map[string]any{}\n\trequest := httpclient.NewCloudRequest30s()\n\tresp, err := request.\n\t\tSetSuccessResult(&result).\n\t\tSetCookies(&http.Cookie{Name: \"symphony\", Value: Conf.GetUser().UserToken}).\n\t\tPost(util.GetCloudServer() + \"/apis/siyuan/inbox/getCloudShorthand?id=\" + id)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"get cloud shorthand failed: %s\", err)\n\t\terr = ErrFailedToConnectCloudServer\n\t\treturn\n\t}\n","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/cloud_service.go#L432-L468","documentation":"In RemoveCloudShorthands, returned when the cloud server responds with HTTP 200 but result['code'] (float64) is non-zero. The server's result['msg'] is extracted via a type assertion to string and wrapped in errors.New. This is a pass-through of a server-side business error from the inbox removal endpoint.","triggerScenarios":"POST /apis/siyuan/inbox/removeCloudShorthands succeeds at the HTTP level but the JSON envelope code != 0, e.g. one of the shorthand ids does not belong to the user, does not exist, or the inbox service rejected the batch. Note: this code path performs a .(string) type assertion on result['msg'] which will panic if msg is not a string.","commonSituations":"A shorthand id in the batch was already deleted; ids belong to another account; server-side inbox inconsistency; concurrent deletion from another device.","solutions":["Show result['msg'] to the user as the specific reason.","Refresh the cloud shorthand list and retry only existing, owned shorthands.","Defensively, the kernel should guard the result['msg'].(string) assertion to avoid a panic when msg is missing or non-string."],"exampleFix":"// before (kernel-side risk): direct assertion can panic\nerr = errors.New(result[\"msg\"].(string))\n\n// after (kernel-side safe)\nmsg, _ := result[\"msg\"].(string)\nif msg == \"\" { msg = \"remove cloud shorthands failed\" }\nerr = errors.New(msg)","handlingStrategy":"try-catch","validationCode":"// Refresh the shorthand list and only delete ids that still exist and are owned\nids := filterOwnedShorthands(cachedIds)","typeGuard":"func isServerBusinessError(err error) bool {\n    return err != nil && !errors.Is(err, model.ErrFailedToConnectCloudServer) && !isAuthError(err)\n}","tryCatchPattern":"if err := model.RemoveCloudShorthands(ids); err != nil {\n    if errors.Is(err, model.ErrFailedToConnectCloudServer) { retry() }\n    else if isAuthError(err) { reloginAndRetry() }\n    else { showUser(err.Error()) /* result[msg] */ }\n}","preventionTips":["Refresh the shorthand list before deleting to drop stale ids.","Kernel-side: guard the result[\"msg\"].(string) assertion with a comma-ok form to avoid panics.","Show the server message verbatim for actionable detail."],"tags":["cloud","inbox","shorthand","api-error","type-assertion","cloud-service"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}