{"record":{"id":"152298b50b739c23","repo":"flipped-aurora/gin-vue-admin","slug":"token-152298","errorCode":null,"errorMessage":"token不能为空","messagePattern":"token不能为空","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/gva/login.go","lineNumber":17,"sourceCode":"package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nfunc newLoginCmd(cfg *CliConfig, configPath string) *cobra.Command {\n\tvar token string\n\tcmd := &cobra.Command{\n\t\tUse:   \"login\",\n\t\tShort: \"保存JWT token到本地配置\",\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tif strings.TrimSpace(token) == \"\" {\n\t\t\t\treturn fmt.Errorf(\"token不能为空\")\n\t\t\t}\n\t\t\tcfg.Token = strings.TrimSpace(token)\n\t\t\treturn saveConfig(configPath, *cfg)\n\t\t},\n\t}\n\tcmd.Flags().StringVar(&token, \"token\", \"\", \"JWT token\")\n\treturn cmd\n}\n\nfunc newSetBaseURLCmd(cfg *CliConfig, configPath string) *cobra.Command {\n\treturn &cobra.Command{\n\t\tUse:   \"set-base-url <url>\",\n\t\tShort: \"更改后台 API 地址并保存到本地配置\",\n\t\tArgs:  cobra.ExactArgs(1),\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tcfg.BaseURL = strings.TrimRight(strings.TrimSpace(args[0]), \"/\")\n\t\t\treturn saveConfig(configPath, *cfg)\n\t\t},","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/cmd/gva/login.go#L1-L35","documentation":"The `gva login` cobra command persists a JWT token into the local gva CLI config. It validates the --token flag and rejects an empty/whitespace-only value because saving an empty token would produce an unusable configuration.","triggerScenarios":"Running `gva login` without the --token flag, or with `--token \"\"` or whitespace-only value.","commonSituations":"Forgetting the flag syntax; shell variable holding the token is unset/empty; copy-paste failed and produced empty string.","solutions":["Pass a valid token: gva login --token <your-jwt-token>","If using a shell variable, confirm it is non-empty before invoking (echo $TOKEN)","Re-copy the token from the login response; ensure no trimming stripped it"],"exampleFix":"// before\ngva login --token \"$TOKEN\"   # TOKEN empty\n// after\n[ -n \"$TOKEN\" ] && gva login --token \"$TOKEN\" || echo 'TOKEN is empty'","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(os.Getenv(\"GVA_TOKEN\")) == \"\" {\n    return fmt.Errorf(\"GVA_TOKEN is empty; run gva login --token <jwt>\")\n}","typeGuard":null,"tryCatchPattern":"if err := loginCmd.Execute(); err != nil {\n    if strings.Contains(err.Error(), \"token不能为空\") {\n        fmt.Println(\"usage: gva login --token <jwt>\")\n    }\n}","preventionTips":["Always pass --token explicitly; never rely on possibly-unset shell vars","Guard with [ -n \"$TOKEN\" ] in scripts","Re-run login after token expiry instead of saving empty values"],"tags":["cli","cobra","jwt","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}