iflytek/astron-agent · error

database url is required

Error message

database url is required

What it means

Config.Validate requires DataBase.Url to be non-empty; this error means the database connection URL/DSN is missing, so the tenant service cannot connect to its datastore. LoadConfig accepts it from the TOML `[database] url` key or the DATABASE_URL env var.

Solutions

  1. Set DATABASE_URL in the environment (e.g. DATABASE_URL=postgres://user:pass@host:5432/tenant?sslmode=disable).
  2. Add `url = "..."` under the [database] section of the TOML config file.
  3. Verify the env var name is exactly DATABASE_URL in the deployment manifest.
  4. Confirm the config file path passed to LoadConfig resolves — bad paths only produce a logged warning, then validation fails.

Example fix

// before
DATABASE_DB_TYPE=postgres
DATABASE_USERNAME=tenant
// after
DATABASE_DB_TYPE=postgres
DATABASE_USERNAME=tenant
DATABASE_URL=postgres://tenant:pass@db:5432/tenant?sslmode=disable
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("DATABASE_URL") == "" {
	return errors.New("DATABASE_URL must be set (e.g. postgres://user:pass@host:5432/db) before startup")
}

Try / catch

cfg, err := config.LoadConfig(path)
if err != nil {
	if strings.Contains(err.Error(), "database url is required") {
		log.Fatalf("DATABASE_URL not set — check Compose/Helm env: %v", err)
	}
	return err
}

Prevention

When it happens

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

Common situations: Omitting the DSN in a minimal dev config, env var name drift (DB_URL/DATABASE_DSN), Helm values missing the database URL, or Compose files relying on a service hostname that never got wired into env.

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/1ba540d044d37b73. Report an issue: GitHub.

Appendix: source

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

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 {
		fmt.Printf("failed to load config from file: %v\n", err)
	}
	// load config from environment variables
	envLoader := NewEnvLoader()
	if err := envLoader.Load(cfg); err != nil {
		return nil, err

View on GitHub (pinned to 5e758547a8)