{"record":{"id":"7ffd9725e97fbec1","repo":"siyuan-note/siyuan","slug":"activation-code-cannot-be-empty","errorCode":null,"errorMessage":"Activation code cannot be empty","messagePattern":"Activation code cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/cloud_service.go","lineNumber":596,"sourceCode":"\t\tlogging.LogErrorf(\"get community user failed: %s\", result[\"msg\"])\n\t\treturn nil, errRequestUserFailed\n\t}\n\n\tdataStr := result[\"data\"].(string)\n\tdata := util.AESDecrypt(dataStr)\n\tuser := &conf.User{}\n\tif err = gulu.JSON.UnmarshalJSON(data, &user); err != nil {\n\t\tlogging.LogErrorf(\"get community user failed: %s\", err)\n\t\treturn nil, errRequestUserFailed\n\t}\n\treturn user, nil\n}\n\nfunc UseActivationcode(code string) (err error) {\n\tcode = util.RemoveInvalid(code)\n\tcode = strings.TrimSpace(code)\n\tif \"\" == code {\n\t\treturn errors.New(Conf.Language(294))\n\t}\n\trequestResult := gulu.Ret.NewResult()\n\trequest := httpclient.NewCloudRequest30s()\n\tresp, err := request.\n\t\tSetSuccessResult(requestResult).\n\t\tSetBody(map[string]string{\"data\": code}).\n\t\tSetCookies(&http.Cookie{Name: \"symphony\", Value: Conf.GetUser().UserToken}).\n\t\tPost(util.GetCloudServer() + \"/apis/siyuan/useActivationcode\")\n\tif err != nil {\n\t\tlogging.LogErrorf(\"check activation code failed: %s\", err)\n\t\treturn ErrFailedToConnectCloudServer\n\t}\n\tif http.StatusOK != resp.StatusCode {\n\t\tlogging.LogErrorf(\"check activation code failed: %d\", resp.StatusCode)\n\t\treturn ErrFailedToConnectCloudServer\n\t}\n\tif 0 != requestResult.Code {\n\t\treturn errors.New(requestResult.Msg)","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/cloud_service.go#L578-L614","documentation":"UseActivationcode rejects an empty activation code. The input is first passed through util.RemoveInvalid and strings.TrimSpace; if nothing remains, the function returns Conf.Language(294) (the localized 'activation code cannot be empty' message). This is intentional input validation before any network call is made.","triggerScenarios":"Call to UseActivationcode with an empty string, a whitespace-only string, or a string composed entirely of characters stripped by util.RemoveInvalid. Triggered from the activation-code UI when the user submits without typing, or programmatically with a blank value.","commonSituations":"User clicks the activate button without entering a code; clipboard paste of whitespace; automation/CLI passing an unset variable; frontend validation bypassed.","solutions":["Validate the code is non-empty on the caller side before invoking UseActivationcode.","Trim and check the input in the UI layer and disable the submit action until a non-empty value is present.","If calling programmatically, guard with `if strings.TrimSpace(code) == \"\" { return }` before the call."],"exampleFix":"// before\nerr := model.UseActivationcode(\"\")\n\n// after\ncode = strings.TrimSpace(code)\nif code == \"\" {\n    return errors.New(\"activation code required\")\n}\nerr := model.UseActivationcode(code)","handlingStrategy":"validation","validationCode":"// Validate activation code before calling UseActivationcode.\nfunc validateActivationCode(code string) error {\n    code = strings.TrimSpace(code)\n    if code == \"\" {\n        return errors.New(\"activation code is required\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim and check the activation code in the UI layer; disable submit until non-empty.","Treat empty-string returns from the model layer as a user-input signal, not a system fault.","When calling programmatically, assert `strings.TrimSpace(code) != \"\"` before the call."],"tags":["validation","activation-code","input","cloud"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}