temporalio/temporal · error

error getting env %v

Error message

error getting env %v

What it means

GetCassandraPort reads CASSANDRA_PORT from the environment for test clusters. If the variable is set but not a valid integer, strconv.Atoi fails and the helper panics. The panic is intentional (test-only code) because a non-numeric port means the test environment is misconfigured.

Source

Thrown at temporal/environment/env.go:87

// GetCassandraAddress return the cassandra address
func GetCassandraAddress() string {
	addr := os.Getenv(cassandraSeedsEnv)
	if addr == "" {
		addr = GetLocalhostIP()
	}
	return addr
}

// GetCassandraPort return the cassandra port
func GetCassandraPort() int {
	port := os.Getenv(cassandraPortEnv)
	if port == "" {
		return cassandraDefaultPort
	}
	p, err := strconv.Atoi(port)
	if err != nil {
		//nolint:forbidigo // used in test code only
		panic(fmt.Sprintf("error getting env %v", cassandraPortEnv))
	}
	return p
}

func GetESAddress() string {
	addr := os.Getenv(esSeedsEnv)
	if addr == "" {
		addr = GetLocalhostIP()
	}
	return addr
}

func GetESPort() int {
	port := os.Getenv(esPortEnv)
	if port == "" {
		return esDefaultPortEnv
	}
	p, err := strconv.Atoi(port)

View on GitHub (pinned to bde624efd1)

Solutions

  1. Fix the CASSANDRA_PORT env var to a plain integer (e.g. 9042)
  2. Unset CASSANDRA_PORT to fall back to the default cassandra port
  3. Sanitize the value (trim spaces, strip anything after ':') before running tests

Example fix

// before
export CASSANDRA_PORT="9042:9042"
// after
export CASSANDRA_PORT=9042
Defensive patterns

Strategy: validation

Validate before calling

port := os.Getenv("CASSANDRA_PORT")
if port != "" {
    if _, err := strconv.Atoi(port); err != nil {
        panic("CASSANDRA_PORT must be an integer, got: " + port)
    }
}

Prevention

When it happens

Trigger: Calling GetCassandraPort (temporal/environment/env.go:87) — directly or via NewTestCluster/NewCassandraConfig/test CQL clients — with CASSANDRA_PORT set to a non-integer value like "9042tcp", "", whitespace, or a host:port string.

Common situations: CI config where the port env var includes quotes or extra characters; docker-compose port mappings like "9042:9042" pasted into the env var; typos in .env files.

Related errors


AI-assisted analysis of temporalio/temporal@bde624efd1 (2026-09-01). Data as JSON: /api/errors/1c7c9441b41d4d25. Report an issue: GitHub.