{"record":{"id":"1ba540d044d37b73","repo":"iflytek/astron-agent","slug":"database-url-is-required","errorCode":null,"errorMessage":"database url is required","messagePattern":"database url is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tenant/config/config.go","lineNumber":48,"sourceCode":"func (c *Config) String() string {\n\treturn fmt.Sprintf(\"Config{Server: %v, DataBase: %v, Log: %v}\", c.Server, c.DataBase, c.Log)\n}\n\nfunc (c *Config) Validate() error {\n\tif c.Server.Port == 0 {\n\t\treturn fmt.Errorf(\"server port is required\")\n\t}\n\tif c.DataBase.DBType == \"\" {\n\t\treturn fmt.Errorf(\"database type is required\")\n\t}\n\tif c.DataBase.UserName == \"\" {\n\t\treturn fmt.Errorf(\"database username is required\")\n\t}\n\tif c.DataBase.Password == \"\" {\n\t\treturn fmt.Errorf(\"database password is required\")\n\t}\n\tif c.DataBase.Url == \"\" {\n\t\treturn fmt.Errorf(\"database url is required\")\n\t}\n\tif c.Log.LogFile == \"\" {\n\t\treturn fmt.Errorf(\"log file is required\")\n\t}\n\treturn nil\n}\n\nfunc LoadConfig(path string) (*Config, error) {\n\tcfg := &Config{}\n\t// load config from local file\n\tlocalLoader := NewLocalLoader(path)\n\tif err := localLoader.Load(cfg); err != nil {\n\t\tfmt.Printf(\"failed to load config from file: %v\\n\", err)\n\t}\n\t// load config from environment variables\n\tenvLoader := NewEnvLoader()\n\tif err := envLoader.Load(cfg); err != nil {\n\t\treturn nil, err","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/tenant/config/config.go#L30-L66","documentation":"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.","triggerScenarios":"LoadConfig(path) -> Config.Validate() returns this when `[database] url` is absent in the TOML and DATABASE_URL is unset/empty.","commonSituations":"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.","solutions":["Set DATABASE_URL in the environment (e.g. DATABASE_URL=postgres://user:pass@host:5432/tenant?sslmode=disable).","Add `url = \"...\"` under the [database] section of the TOML config file.","Verify the env var name is exactly DATABASE_URL in the deployment manifest.","Confirm the config file path passed to LoadConfig resolves — bad paths only produce a logged warning, then validation fails."],"exampleFix":"// before\nDATABASE_DB_TYPE=postgres\nDATABASE_USERNAME=tenant\n// after\nDATABASE_DB_TYPE=postgres\nDATABASE_USERNAME=tenant\nDATABASE_URL=postgres://tenant:pass@db:5432/tenant?sslmode=disable","handlingStrategy":"validation","validationCode":"if os.Getenv(\"DATABASE_URL\") == \"\" {\n\treturn errors.New(\"DATABASE_URL must be set (e.g. postgres://user:pass@host:5432/db) before startup\")\n}","typeGuard":null,"tryCatchPattern":"cfg, err := config.LoadConfig(path)\nif err != nil {\n\tif strings.Contains(err.Error(), \"database url is required\") {\n\t\tlog.Fatalf(\"DATABASE_URL not set — check Compose/Helm env: %v\", err)\n\t}\n\treturn err\n}","preventionTips":["Set DATABASE_URL in every environment's env block next to DATABASE_DB_TYPE","Standardize on one env var name (DATABASE_URL) across services to avoid drift","Include a fully populated [database] section in the example config","Run a config-validation job in CI against rendered Helm/Compose output"],"tags":["configuration","database","go","tenant-service"],"backgroundTag":"missing-required-config-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}