Billionmail/BillionMail · error
failed to get validate code: %w
Error message
failed to get validate code: %w
What it means
The login page calls GetValidateCode to fetch a captcha image; this error wraps any failure from rbac.GetCaptcha(), which generates the captcha ID and a base64 PNG. The wrapped cause tells you whether generation (image/font/code store) or persistence of the captcha failed. Users cannot get a captcha and thus cannot log in when a captcha is required.
Source
Thrown at core/internal/controller/rbac/rbac_v1_get_validate_code.go:25
"fmt"
"github.com/gogf/gf/v2/frame/g"
"billionmail-core/api/rbac/v1"
)
func (c *ControllerV1) GetValidateCode(ctx context.Context, req *v1.GetValidateCodeReq) (res *v1.GetValidateCodeRes, err error) {
res = &v1.GetValidateCodeRes{}
clientIp := g.RequestFromCtx(ctx).GetClientIp()
cacheKey := fmt.Sprintf("USER_LOGIN_RETRIES:%s", clientIp)
res.Data.LoginRetries, res.Data.MustValidateCode = public.GetCache(cacheKey).(int)
res.Data.MaxLoginRetries = 5
res.Data.ValidateCodeId, res.Data.ValidateCodeBase64, err = rbac.GetCaptcha()
if err != nil {
err = fmt.Errorf("failed to get validate code: %w", err)
return
}
res.SetSuccess(public.LangCtx(ctx, "Success"))
return
}
View on GitHub (pinned to fc36c76c05)
Solutions
- Check the cache/redis backend used by the captcha service is running
- Look at logs for the wrapped inner error to identify generation vs storage failure
- Restart the app after restoring the captcha store
- If captchas are not needed, ensure the login-retry counter is below the threshold so mustValidateCode stays false
Defensive patterns
Strategy: retry
Validate before calling
// check whether captcha is required first const status = await api.getLoginState(); if (!status.data.mustValidateCode) skipCaptcha();
Try / catch
try {
const code = await api.getValidateCode();
} catch (e) {
if (e.message.includes('validate code')) {
await delay(1000);
return getValidateCode(); // retry, transient store issue
}
} Prevention
- Keep Redis/cache backend healthy (docker healthchecks)
- Pin captcha library versions in go.mod
- Alert on captcha generation failures
- Cache failure counters to avoid hammering the endpoint
When it happens
Trigger: GET validate-code when GetCaptcha() fails: its internal captcha store (Redis/cache) is down, image generation fails, or captcha library misconfiguration after a dependency change.
Common situations: Redis unavailable in the deployment; captcha dependency version change breaking image rendering; disk/font issues in minimal container images.
Related errors
- Login failed too many times, please try again after %d secon
- Validation code ID and code cannot be empty
- Invalid validation code
- Invalid username or password
- Failed to get account roles
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/bee6fad47f8a0ea1.
Report an issue: GitHub.