{"record":{"id":"b79332192a347ba4","repo":"iflytek/astron-agent","slug":"server-port-is-required","errorCode":null,"errorMessage":"server port is required","messagePattern":"server port is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tenant/config/config.go","lineNumber":36,"sourceCode":"\t} `toml:\"database\"`\n\n\tLog struct {\n\t\tLogFile string `toml:\"path\"`\n\t} `toml:\"log\"`\n\n\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}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/tenant/config/config.go#L18-L54","documentation":"Config.Validate in core/tenant/config/config.go:34 fails-fast on required fields, first checking Server.Port. This error means the loaded configuration has no server port set (zero value 0), so the tenant service would have nothing to listen on. LoadConfig calls Validate after merging the local TOML file and SERVICE_* environment variables.","triggerScenarios":"LoadConfig(path) returns this when after both the local config file load and the EnvLoader pass, cfg.Server.Port is still 0 — i.e. the TOML [service] section has no `port` key and SERVICE_PORT is unset or empty.","commonSituations":"Missing or wrong path passed to LoadConfig (the file loader only prints a warning and continues), a TOML file missing the [service] section, deploying without the SERVICE_PORT environment variable set in the container/Helm values, or a typo like SERVICEPORT.","solutions":["Set SERVICE_PORT in the environment (e.g. SERVICE_PORT=8080) before starting the tenant service.","Add `port = <port>` under the [service] section of the TOML config file and confirm LoadConfig receives the correct path.","Verify the config file path passed to LoadConfig — a bad path only logs 'failed to load config from file' and falls through to this validation error.","Check that all required env vars (SERVICE_PORT, DATABASE_*, LOG_PATH) are present in the deployment manifest; fix the first missing one to clear this error."],"exampleFix":"// before: docker-compose env\n//   DATABASE_URL: postgres://...\n// after: add the port\n//   SERVICE_PORT: 8080\n//   DATABASE_URL: postgres://...","handlingStrategy":"validation","validationCode":"if os.Getenv(\"SERVICE_PORT\") == \"\" {\n\treturn errors.New(\"SERVICE_PORT must be set (e.g. 8080) before startup\")\n}","typeGuard":null,"tryCatchPattern":"cfg, err := config.LoadConfig(path)\nif err != nil {\n\tif strings.Contains(err.Error(), \"server port is required\") {\n\t\tlog.Fatalf(\"missing SERVICE_PORT or [service] port in config: %v\", err)\n\t}\n\treturn err\n}","preventionTips":["Always set SERVICE_PORT in container/Helm env alongside the other required vars","Keep a checked-in example config with all [service]/[database]/[log] keys populated","Validate deployment manifests in CI by calling LoadConfig against them","Remember file-load failures in LoadConfig are only logged — verify the config path arg"],"tags":["configuration","startup","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"}