{"record":{"id":"ff79237265475f41","repo":"iflytek/astron-agent","slug":"mysql-username-is-empty","errorCode":null,"errorMessage":"mysql username is empty","messagePattern":"mysql username is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/tenant/tools/database/database.go","lineNumber":74,"sourceCode":"\t}\n\tclient.SetMaxOpenConns(conf.DataBase.MaxOpenConns)\n\tclient.SetMaxIdleConns(conf.DataBase.MaxIdleConns)\n\tif err := client.Ping(); err != nil {\n\t\treturn err\n\t}\n\n\tif err := initializeMysqlClient(client, conf.TenantBootstrap); err != nil {\n\t\t_ = client.Close()\n\t\treturn err\n\t}\n\n\tdb.mysql = client\n\treturn nil\n}\n\nfunc parseMysqlConfig(conf *config.Config) (string, *mysql.Config, error) {\n\tif len(conf.DataBase.UserName) == 0 {\n\t\treturn \"\", nil, errors.New(\"mysql username is empty\")\n\t}\n\tif len(conf.DataBase.Password) == 0 {\n\t\treturn \"\", nil, errors.New(\"mysql password is empty\")\n\t}\n\tif len(conf.DataBase.Url) == 0 {\n\t\treturn \"\", nil, errors.New(\"mysql url is empty\")\n\t}\n\tif err := conf.TenantBootstrap.Validate(); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"invalid tenant bootstrap credentials: %w\", err)\n\t}\n\n\tdsn := fmt.Sprintf(\"%s:%s@tcp%s\", conf.DataBase.UserName, conf.DataBase.Password, conf.DataBase.Url)\n\tparsedDsn, err := mysql.ParseDSN(dsn)\n\tif err != nil {\n\t\treturn \"\", nil, err\n\t}\n\treturn dsn, parsedDsn, nil\n}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/tenant/tools/database/database.go#L56-L92","documentation":"parseMysqlConfig rejects the tenant service configuration when DataBase.UserName is empty, failing fast before building the DSN/connection. It is a startup config guard — the MySQL client cannot be constructed without credentials.","triggerScenarios":"buildMysql → parseMysqlConfig with a config whose database.userName is empty or absent.","commonSituations":"MySQL credential env var not injected into the container, Helm/Compose secret not mounted, key typo in config file, or default config template with empty username.","solutions":["Set database.userName in the tenant service config or its backing env/secret","Verify the secret/config is mounted and readable by the tenant service pod","Re-check Compose/Helm values that template the MySQL username","Restart the service after supplying the username"],"exampleFix":"// before\ndatabase:\n  userName: \"\"\n// after\ndatabase:\n  userName: \"tenant_user\"","handlingStrategy":"validation","validationCode":"if conf.DataBase.UserName == \"\" { return errors.New(\"mysql username must be configured\") }","typeGuard":null,"tryCatchPattern":"if _, _, err := parseMysqlConfig(conf); err != nil { log.Fatalf(\"mysql config invalid: %v\", err) }","preventionTips":["Inject DB credentials via secrets, never hardcode","Add a startup config sanity check for user/password/url","Verify secret mounts in deployment manifests"],"tags":["go","mysql","config","database"],"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"}