iflytek/astron-agent · error

server port is required

Error message

server port is required

What it means

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.

Solutions

  1. Set SERVICE_PORT in the environment (e.g. SERVICE_PORT=8080) before starting the tenant service.
  2. Add `port = <port>` under the [service] section of the TOML config file and confirm LoadConfig receives the correct path.
  3. 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.
  4. 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.

Example fix

// before: docker-compose env
//   DATABASE_URL: postgres://...
// after: add the port
//   SERVICE_PORT: 8080
//   DATABASE_URL: postgres://...
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("SERVICE_PORT") == "" {
	return errors.New("SERVICE_PORT must be set (e.g. 8080) before startup")
}

Try / catch

cfg, err := config.LoadConfig(path)
if err != nil {
	if strings.Contains(err.Error(), "server port is required") {
		log.Fatalf("missing SERVICE_PORT or [service] port in config: %v", err)
	}
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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

Appendix: source

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

	} `toml:"database"`

	Log struct {
		LogFile string `toml:"path"`
	} `toml:"log"`

	// TenantBootstrap is loaded only from deployment-managed environment
	// variables or credential files. It is intentionally omitted from String so
	// credentials cannot be exposed by routine configuration logging.
	TenantBootstrap TenantBootstrapCredentials
}

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
}

View on GitHub (pinned to 5e758547a8)