iflytek/astron-agent · error

invalid SERVICE_PORT

Error message

invalid SERVICE_PORT: %v

What it means

EnvLoader.setServicePort parses the SERVICE_PORT environment variable with fmt.Sscanf("%d") when it is non-empty; this error is returned when the value cannot be parsed as an integer (Sscanf returns an error or parses zero fields). It is surfaced from EnvLoader.Load, which LoadConfig propagates, aborting startup. Note the wrapped error is often nil when n != 1 without err, so the message may end with '%!v(MISSING)'-style output for non-numeric input.

Solutions

  1. Set SERVICE_PORT to a bare integer (e.g. SERVICE_PORT=8080) and restart the service.
  2. Print the actual value (`printenv SERVICE_PORT | cat -A`) to reveal hidden characters or extra text and clean it up in the deployment manifest.
  3. If the value comes from Helm/Compose templating, check that the template interpolates to a plain number and isn't concatenating a hostname or protocol.
  4. For robustness in code, prefer strconv.Atoi over fmt.Sscanf to get a clearer parse error message.

Example fix

// before
SERVICE_PORT="http://localhost:8080"
// after
SERVICE_PORT=8080
Defensive patterns

Strategy: validation

Validate before calling

if v := os.Getenv("SERVICE_PORT"); v != "" {
	if _, err := strconv.Atoi(v); err != nil {
		return fmt.Errorf("SERVICE_PORT must be a plain integer, got %q", v)
	}
}

Try / catch

_, err := config.LoadConfig(path)
if err != nil && strings.HasPrefix(err.Error(), "invalid SERVICE_PORT") {
	log.Fatalf("SERVICE_PORT=%q is not an integer: %v", os.Getenv("SERVICE_PORT"), err)
}

Prevention

When it happens

Trigger: SERVICE_PORT set to a non-numeric or partially numeric value such as "8080px", "localhost:8080", "eight-thousand", an empty-ish string like " " (whitespace only), or "" — actually empty strings are skipped by Load, so any non-empty non-integer value triggers it.

Common situations: Typos in Compose/Helm values, quoting a port together with extra text, pasting 'PORT=8080' (with prefix) into the value, YAML coercion to string '8080 ' with invisible characters, or locale-formatted numbers.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/b40ed7ac1f282006. Report an issue: GitHub.

Appendix: source

Thrown at core/tenant/config/env_loader.go:45

		{"DATABASE_MAX_OPEN_CONNS", l.setDatabaseMaxOpenConns},
		{"DATABASE_MAX_IDLE_CONNS", l.setDatabaseMaxIdleConns},
		{"LOG_PATH", l.setLogPath},
	}

	for _, mapping := range mappings {
		if value := os.Getenv(mapping.envKey); value != "" {
			if err := mapping.setValue(cfg, value); err != nil {
				return err
			}
		}
	}

	return nil
}

func (l *EnvLoader) setServicePort(cfg *Config, value string) error {
	if n, err := fmt.Sscanf(value, "%d", &cfg.Server.Port); err != nil || n != 1 {
		return fmt.Errorf("invalid SERVICE_PORT: %v", err)
	}
	return nil
}

func (l *EnvLoader) setServiceLocation(cfg *Config, value string) error {
	cfg.Server.Location = value
	return nil
}

func (l *EnvLoader) setDatabaseDBType(cfg *Config, value string) error {
	cfg.DataBase.DBType = value
	return nil
}

func (l *EnvLoader) setDatabaseUsername(cfg *Config, value string) error {
	cfg.DataBase.UserName = value
	return nil
}

View on GitHub (pinned to 5e758547a8)