JuliusBrussee/caveman · error
tenantkey: safe month is required
Error message
tenantkey: safe month is required
What it means
MonthlySpend builds a tenant-scoped spend key and requires the month component to pass safePart (a non-empty, characters-safe segment). If the month is empty or contains unsafe characters (which could alter key structure), the library returns this error rather than producing a malformed or colliding key.
Solutions
- Format the month canonically before calling: t.Format("2006-01") produces "2026-09", which is safePart-safe.
- Validate/normalize the month input (strings.TrimSpace, reject empties) at the caller boundary and return a descriptive error to the user.
- If the month comes from user input or a path parameter, whitelist-regex it (e.g. ^\d{4}-\d{2}$) before invoking MonthlySpend.
Example fix
// before
key, err := tenantkey.MonthlySpend(org, proj, req.URL.Query().Get("month")) // may be "2026/09" or ""
// after
month := strings.TrimSpace(req.URL.Query().Get("month"))
if !regexp.MustCompile(`^\d{4}-\d{2}$`).MatchString(month) {
return errors.New("month must be in YYYY-MM format")
}
key, err := tenantkey.MonthlySpend(org, proj, month) Defensive patterns
Strategy: validation
Validate before calling
var monthRe = regexp.MustCompile(`^\d{4}-\d{2}$`)
func validMonth(m string) bool { return monthRe.MatchString(strings.TrimSpace(m)) } Try / catch
key, err := tenantkey.MonthlySpend(org, proj, month)
if err != nil && strings.Contains(err.Error(), "safe month is required") {
return fmt.Errorf("month %q must be a non-empty YYYY-MM token", month)
} Prevention
- Always produce month values with time.Format("2006-01")
- Reject empty/unsafe segments at the request boundary with a clear user-facing error
- Add a unit test that feeds malformed months ("", "2026/09") to catch regressions
When it happens
Trigger: Calling tenantkey.MonthlySpend(orgID, projectID, month) with month = "" or a month containing unsafe characters (e.g. "2026/09", "2026-09 extra", values with ':' or whitespace) instead of a clean token like "2026-09".
Common situations: A missing month parameter from a report/CLI command; a date formatted with a slash ("2026/09") or locale text ("September 2026"); a time.Time formatted with the wrong layout; upstream data with untrimmed whitespace.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- tenantkey: safe month and request id are required
- arm must be or
- CAVEMAN_CCR_MAX_BYTES must be a positive integer
- ccr max storage bytes must be positive
- ccr: unknown lifecycle
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/04ed0e31f07e3c59.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/tenantkey/tenantkey.go:26
)
// CavePlan returns worker/gateway shared published-plan key.
func CavePlan(organizationID, projectID string) (string, error) {
prefix, err := projectPrefix("plan", organizationID, projectID)
if err != nil {
return "", err
}
return prefix, nil
}
// MonthlySpend returns gateway/control-api shared monthly spend key.
func MonthlySpend(organizationID, projectID, month string) (string, error) {
prefix, err := projectPrefix("spend", organizationID, projectID)
if err != nil {
return "", err
}
if !safePart(month) {
return "", errors.New("tenantkey: safe month is required")
}
return prefix + ":" + month, nil
}
// MonthlySpendEvent returns idempotency-marker key for one spend event.
func MonthlySpendEvent(organizationID, projectID, month, requestID string) (string, error) {
prefix, err := projectPrefix("spend-event", organizationID, projectID)
if err != nil {
return "", err
}
if !safePart(month) || !safePart(requestID) {
return "", errors.New("tenantkey: safe month and request id are required")
}
return prefix + ":" + month + ":" + requestID, nil
}
func projectPrefix(namespace, organizationID, projectID string) (string, error) {
if !safePart(organizationID) || !safePart(projectID) {View on GitHub (pinned to 3ee70a1026)