Wei-Shaw/sub2api · error

account name is required

Error message

account name is required

What it means

Returned by validateDataAccount (backend/internal/handler/admin/account_data.go:680) when an accounts[] entry's name is empty after TrimSpace. Name is the first per-account field checked, followed by platform, type, and credentials, so this error means the entry failed at the very first precondition.

Source

Thrown at backend/internal/handler/admin/account_data.go:680

		return errors.New("proxy port is invalid")
	}
	switch item.Protocol {
	case "http", "https", "socks5", "socks5h":
	default:
		return fmt.Errorf("proxy protocol is invalid: %s", item.Protocol)
	}
	if item.Status != "" {
		normalizedStatus := normalizeProxyStatus(item.Status)
		if normalizedStatus != service.StatusActive && normalizedStatus != "inactive" {
			return fmt.Errorf("proxy status is invalid: %s", item.Status)
		}
	}
	return nil
}

func validateDataAccount(item DataAccount) error {
	if strings.TrimSpace(item.Name) == "" {
		return errors.New("account name is required")
	}
	if strings.TrimSpace(item.Platform) == "" {
		return errors.New("account platform is required")
	}
	if strings.TrimSpace(item.Type) == "" {
		return errors.New("account type is required")
	}
	if len(item.Credentials) == 0 {
		return errors.New("account credentials is required")
	}
	switch item.Type {
	case service.AccountTypeOAuth, service.AccountTypeSetupToken, service.AccountTypeAPIKey, service.AccountTypeUpstream:
	default:
		return fmt.Errorf("account type is invalid: %s", item.Type)
	}
	if item.RateMultiplier != nil && *item.RateMultiplier < 0 {
		return errors.New("rate_multiplier must be >= 0")
	}

View on GitHub (pinned to 073e92d171)

Solutions

  1. Set a non-empty name on every account entry (e.g. 'openai-main').
  2. If generating payloads, always emit a name — the import does not auto-generate one.
  3. Trim and check required fields client-side before submit.

Example fix

// before
{ "platform": "openai", "type": "oauth", "credentials": { ... } }

// after
{ "name": "openai-main", "platform": "openai", "type": "oauth", "credentials": { ... } }
Defensive patterns

Strategy: validation

Validate before calling

function hasAccountName(entry: Record<string, unknown>): boolean {
  return typeof entry.name === 'string' && entry.name.trim() !== ''
}

Type guard

function hasRequiredAccountStrings(e: unknown, keys: string[]): e is Record<string, string> {
  if (typeof e !== 'object' || e === null) return false
  const o = e as Record<string, unknown>
  return keys.every((k) => typeof o[k] === 'string' && (o[k] as string).trim() !== '')
}

Prevention

When it happens

Trigger: An account object with name missing, blank, or whitespace-only; a serializer dropping the name field for auto-named accounts.

Common situations: Minimal hand-written imports that skip display names; exports where name was optional; front-end form allowing empty name.

Related errors


AI-assisted analysis of Wei-Shaw/sub2api@073e92d171 (2026-08-15). Data as JSON: /api/errors/e2d8237717b9a1c7. Report an issue: GitHub.