{"record":{"id":"89fd633d42a4d90f","repo":"iflytek/astron-agent","slug":"database-username-is-required","errorCode":null,"errorMessage":"database username is required","messagePattern":"database username is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tenant/config/config.go","lineNumber":42,"sourceCode":"\t// TenantBootstrap is loaded only from deployment-managed environment\n\t// variables or credential files. It is intentionally omitted from String so\n\t// credentials cannot be exposed by routine configuration logging.\n\tTenantBootstrap TenantBootstrapCredentials\n}\n\nfunc (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 {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/tenant/config/config.go#L24-L60","documentation":"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.","triggerScenarios":"LoadConfig(path) -> Config.Validate() returns this when `[database] username` is missing in the TOML and DATABASE_USERNAME is unset/empty.","commonSituations":"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.","solutions":["Set DATABASE_USERNAME in the environment (e.g. DATABASE_USERNAME=tenant).","Add `username = \"...\"` under the [database] section of the TOML config file.","If injecting from a K8s Secret, verify envFrom/secretKeyRef is configured and the secret key matches DATABASE_USERNAME.","Check the config file path passed to LoadConfig is correct; file-load failures are only logged as a warning."],"exampleFix":"// before\nDATABASE_URL=postgres://localhost:5432/tenant\n// after\nDATABASE_USERNAME=tenant\nDATABASE_URL=postgres://localhost:5432/tenant","handlingStrategy":"validation","validationCode":"if os.Getenv(\"DATABASE_USERNAME\") == \"\" {\n\treturn errors.New(\"DATABASE_USERNAME must be set before tenant startup\")\n}","typeGuard":null,"tryCatchPattern":"cfg, err := config.LoadConfig(path)\nif err != nil {\n\tif strings.Contains(err.Error(), \"database username is required\") {\n\t\tlog.Fatalf(\"DATABASE_USERNAME not set — check Secret mounting: %v\", err)\n\t}\n\treturn err\n}","preventionTips":["Inject DB credentials via envFrom Secret and verify key names match loader expectations","Diff dev/prod manifests so no required env var is dropped between environments","Keep a populated example config.toml under version control","Validate config early with a startup preflight that calls LoadConfig"],"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"}