reacherhq/check-if-email-exists · critical

Invalid port

Error message

Invalid port: {}

What it means

When the PORT environment variable is set, run_warp_server parses it as u16; if it fails to parse, it panics with 'Invalid port: {}'. This fail-fast guard catches misconfigured port values before binding the HTTP server.

Solutions

  1. Set PORT to a valid numeric port between 1 and 65535
  2. Unset PORT so the server falls back to config.http_port
  3. Trim whitespace/quotes from the value in your .env or orchestrator config

Example fix

// before
PORT="8o80" docker run reacher-backend
// after
PORT=8080 docker run reacher-backend
Defensive patterns

Strategy: validation

Validate before calling

if let Ok(port) = std::env::var("PORT") {
    let ok = port.trim().parse::<u16>().is_ok();
    if !ok { eprintln!("PORT '{}' is not a valid u16", port); std::process::exit(1); }
}

Type guard

fn is_valid_port(s: &str) -> bool { s.trim().parse::<u16>().is_ok() }

Prevention

When it happens

Trigger: PORT env var set to a non-numeric string, a value above 65535, an empty string, or containing whitespace when run_warp_server starts.

Common situations: PLATFORM sets PORT to a named value or blank; quoting issues in docker-compose leaving quotes in the value; trailing newline in an .env file.

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 reacherhq/check-if-email-exists@81da93e8a4 (2026-09-11). Data as JSON: /api/errors/34044c2ed7636664. Report an issue: GitHub.

Appendix: source

Thrown at backend/src/http/mod.rs:77

/// This function starts the Warp server and listens for incoming requests.
/// It returns a `Result` indicating whether the server started successfully or
/// encountered an error, as well as an optional `JobRunnerHandle` if the bulk
/// job listener is enabled. The handle can be used to stop the listener or to
/// keep it alive.
pub async fn run_warp_server(
	config: Arc<BackendConfig>,
) -> Result<Option<JobRunnerHandle>, anyhow::Error> {
	let host = config
		.http_host
		.parse::<IpAddr>()
		.unwrap_or_else(|_| panic!("Invalid host: {}", config.http_host));
	// For backwards compatibility, we allow the port to be set via the
	// environment variable PORT, instead of the new configuration file. The
	// PORT environment variable takes precedence.
	let port = env::var("PORT")
		.map(|port: String| {
			port.parse::<u16>()
				.unwrap_or_else(|_| panic!("Invalid port: {}", port))
		})
		.unwrap_or(config.http_port);

	let routes = create_routes(Arc::clone(&config));

	// Run v0 bulk job listener.
	let is_bulk_enabled = env::var("RCH_ENABLE_BULK").unwrap_or_else(|_| "0".into()) == "1";
	let runner = if is_bulk_enabled {
		let pg_pool = config.get_pg_pool().expect(
			"Please set the RCH__STORAGE__POSTGRES__DB_URL environment when RCH_ENABLE_BULK is set",
		);
		let runner = v0::bulk::create_job_registry(&pg_pool).await?;
		Some(runner)
	} else {
		None
	};

	info!(target: LOG_TARGET, host=?host,port=?port, "Server is listening");

View on GitHub (pinned to 81da93e8a4)