iflytek/astron-agent · error

database username is required

Error message

database username is required

What it means

Config.Validate requires DataBase.UserName to be non-empty; this error means no database username was provided. The tenant service uses it to open its DB connection, so startup is aborted. LoadConfig checks the TOML file and DATABASE_USERNAME env var as sources.

Solutions

  1. Set DATABASE_USERNAME in the environment (e.g. DATABASE_USERNAME=tenant).
  2. Add `username = "..."` under the [database] section of the TOML config file.
  3. If injecting from a K8s Secret, verify envFrom/secretKeyRef is configured and the secret key matches DATABASE_USERNAME.
  4. Check the config file path passed to LoadConfig is correct; file-load failures are only logged as a warning.

Example fix

// before
DATABASE_URL=postgres://localhost:5432/tenant
// after
DATABASE_USERNAME=tenant
DATABASE_URL=postgres://localhost:5432/tenant
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("DATABASE_USERNAME") == "" {
	return errors.New("DATABASE_USERNAME must be set before tenant startup")
}

Try / catch

cfg, err := config.LoadConfig(path)
if err != nil {
	if strings.Contains(err.Error(), "database username is required") {
		log.Fatalf("DATABASE_USERNAME not set — check Secret mounting: %v", err)
	}
	return err
}

Prevention

When it happens

Trigger: LoadConfig(path) -> Config.Validate() returns this when `[database] username` is missing in the TOML and DATABASE_USERNAME is unset/empty.

Common situations: K8s Secret not mounted or key named differently (DB_USER vs DATABASE_USERNAME), config file with a `[database]` section missing the username key, or provisioning a DB user and forgetting to wire it into the service config.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/89fd633d42a4d90f. Report an issue: GitHub.

Appendix: source

Thrown at core/tenant/config/config.go:42

	// TenantBootstrap is loaded only from deployment-managed environment
	// variables or credential files. It is intentionally omitted from String so
	// credentials cannot be exposed by routine configuration logging.
	TenantBootstrap TenantBootstrapCredentials
}

func (c *Config) String() string {
	return fmt.Sprintf("Config{Server: %v, DataBase: %v, Log: %v}", c.Server, c.DataBase, c.Log)
}

func (c *Config) Validate() error {
	if c.Server.Port == 0 {
		return fmt.Errorf("server port is required")
	}
	if c.DataBase.DBType == "" {
		return fmt.Errorf("database type is required")
	}
	if c.DataBase.UserName == "" {
		return fmt.Errorf("database username is required")
	}
	if c.DataBase.Password == "" {
		return fmt.Errorf("database password is required")
	}
	if c.DataBase.Url == "" {
		return fmt.Errorf("database url is required")
	}
	if c.Log.LogFile == "" {
		return fmt.Errorf("log file is required")
	}
	return nil
}

func LoadConfig(path string) (*Config, error) {
	cfg := &Config{}
	// load config from local file
	localLoader := NewLocalLoader(path)
	if err := localLoader.Load(cfg); err != nil {

View on GitHub (pinned to 5e758547a8)