iflytek/astron-agent · error

database type is required

Error message

database type is required

What it means

Config.Validate requires DataBase.DBType to be non-empty; this error indicates the database driver/type (e.g. postgres, mysql) was never configured. LoadConfig merges the TOML file and DATABASE_* environment variables before validating, so the value was absent from both sources.

Solutions

  1. Set DATABASE_DB_TYPE in the environment (e.g. DATABASE_DB_TYPE=postgres).
  2. Add `dbType = "postgres"` under the [database] section of the TOML config file.
  3. Verify the env var name is exactly DATABASE_DB_TYPE (check for typos like DATABASE_DBTYPE).
  4. Confirm the config file path passed to LoadConfig is valid, since a failed file load is only logged, not returned.

Example fix

// before
[database]
username = "tenant"
// after
[database]
dbType = "postgres"
username = "tenant"
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("DATABASE_DB_TYPE") == "" {
	return errors.New("DATABASE_DB_TYPE must be set (e.g. postgres) before startup")
}

Try / catch

cfg, err := config.LoadConfig(path)
if err != nil {
	if strings.Contains(err.Error(), "database type is required") {
		log.Fatalf("DATABASE_DB_TYPE not set: %v", err)
	}
	return err
}

Prevention

When it happens

Trigger: LoadConfig(path) -> Config.Validate() returns this when the TOML `[database] dbType` key is missing/empty and the DATABASE_DB_TYPE environment variable is unset or empty.

Common situations: Fresh deployments with a partial .toml, renaming the env var (e.g. DB_TYPE instead of DATABASE_DB_TYPE), secrets/config ConfigMaps not mounted, or Helm values omitting the database type key.

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/0dd8a4d7b11068a3. Report an issue: GitHub.

Appendix: source

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

		LogFile string `toml:"path"`
	} `toml:"log"`

	// 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{}

View on GitHub (pinned to 5e758547a8)