flipped-aurora/gin-vue-admin · error
未知错误
Error message
未知错误
What it means
TokenValid is the sentinel error returned by ParseToken when token parsing fails with an error that matches none of the specific JWT sentinels (expired, not-valid-yet, malformed, bad signature, invalid). It is the catch-all '未知错误' bucket for unexpected token validation failures.
Source
Thrown at server/utils/jwt.go:18
package utils
import (
"context"
"errors"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
jwt "github.com/golang-jwt/jwt/v5"
)
type JWT struct {
SigningKey []byte
}
var (
TokenValid = errors.New("未知错误")
TokenExpired = errors.New("token已过期")
TokenNotValidYet = errors.New("token尚未激活")
TokenMalformed = errors.New("这不是一个token")
TokenSignatureInvalid = errors.New("无效签名")
TokenInvalid = errors.New("无法处理此token")
)
func NewJWT() *JWT {
return &JWT{
[]byte(global.GVA_CONFIG.JWT.SigningKey),
}
}
func (j *JWT) CreateClaims(baseClaims request.BaseClaims) request.CustomClaims {
bf, _ := ParseDuration(global.GVA_CONFIG.JWT.BufferTime)
ep, _ := ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
claims := request.CustomClaims{
BaseClaims: baseClaims,View on GitHub (pinned to 3136500ef3)
Solutions
- Log the underlying raw error from ParseToken to see which jwt library error fell through to the default branch.
- Verify JWT.SigningKey in config matches the one used to issue the token; regenerate a token with the correct key.
- Confirm the client is sending a properly formed 'Bearer <token>' header and the token is not empty.
- Check golang-jwt/jwt version compatibility between token issuance and validation code paths.
Example fix
// before
token := c.Request.Header.Get("x-token") // empty or wrong key
claims, err := utils.ParseToken(token) // 未知错误
// after
if token == "" {
c.AbortWithStatusJSON(401, ...)
return
}
claims, err := utils.ParseToken(token) // valid token signed with GVA_CONFIG.JWT.SigningKey Defensive patterns
Strategy: try-catch
Validate before calling
if token == "" {
return errors.New("token is empty")
}
if parts := strings.Split(token, "."); len(parts) != 3 {
return errors.New("token is not a JWT")
} Type guard
func looksLikeJWT(s string) bool {
parts := strings.Split(s, ".")
return len(parts) == 3 && parts[0] != "" && parts[2] != ""
} Try / catch
claims, err := utils.ParseToken(token)
if err != nil {
switch {
case errors.Is(err, utils.TokenExpired):
// re-login/refresh
case errors.Is(err, utils.TokenNotValidYet), errors.Is(err, utils.TokenMalformed),
errors.Is(err, utils.TokenSignatureInvalid), errors.Is(err, utils.TokenInvalid),
errors.Is(err, utils.TokenValid):
// reject with 401
default:
log rawErr // unmapped fallback: investigate signing config
}
} Prevention
- Keep JWT.SigningKey consistent across all environments that share tokens
- Check errors.Is against every jwt sentinel exported in server/utils/jwt.go and log the raw error for the default branch
- Validate the Authorization/x-token header shape before calling ParseToken
When it happens
Trigger: ParseToken receives a token whose jwt.Parse error does not match the known sentinel switch: e.g. an entirely empty token string, an unexpected signing method, or a token signed with a different key causing an unmapped error path depending on library version.
Common situations: Proxy stripping/replacing the Authorization header value; client sending a token from a different deployment with a different SigningKey; misconfigured JWT.SigningKey in config.yaml; golang-jwt version upgrades changing error surfaces.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/2f4cee41b6df4928.
Report an issue: GitHub.