reacherhq/check-if-email-exists · error · anyhow::Error

Calling must_worker_config on a non-worker backend

Error message

Calling must_worker_config on a non-worker backend

What it means

must_worker_config is only meaningful for backends running in worker mode. Calling it on a backend whose config does not enable the worker falls through all match arms to a catch-all that bails with 'Calling must_worker_config on a non-worker backend'.

Solutions

  1. Only call must_worker_config when config.worker.enable is true
  2. Check backend config mode before requesting the worker config
  3. If the backend should be a worker, set worker.enable = true in the config

Example fix

// before
let must_worker = backend.must_worker_config().await?;
// after
if backend.config.worker.enable {
    let must_worker = backend.must_worker_config().await?;
}
Defensive patterns

Strategy: type-guard

Validate before calling

if !config.worker.enable {
    eprintln!("must_worker_config requires worker.enable = true");
}

Type guard

fn is_worker_backend(config: &BackendConfig) -> bool { config.worker.enable }

Try / catch

match backend.must_worker_config().await {
    Err(e) if e.to_string().contains("non-worker backend") => {
        eprintln!("Not a worker backend; skip worker setup");
    }
    Err(e) => return Err(e),
    Ok(cfg) => cfg,
}

Prevention

When it happens

Trigger: Calling backend.must_worker_config() when worker.enable is false or the worker section is absent in BackendConfig.

Common situations: Shared code path that unconditionally calls must_worker_config for both API and worker deployments; a refactor renaming the enable flag so it defaults to false.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of reacherhq/check-if-email-exists@81da93e8a4 (2026-09-11). Data as JSON: /api/errors/e5540be29e478441. Report an issue: GitHub.

Appendix: source

Thrown at backend/src/config.rs:185

			everything_else: EverythingElseVerifMethod::Smtp(default_smtp_config),
		}
	}

	/// Get the worker configuration.
	///
	/// # Panics
	///
	/// Panics if the worker configuration is missing.
	pub fn must_worker_config(&self) -> Result<MustWorkerConfig, anyhow::Error> {
		match (self.worker.enable, &self.worker.rabbitmq, &self.channel) {
			(true, Some(rabbitmq), Some(channel)) => Ok(MustWorkerConfig {
				channel: channel.clone(),
				rabbitmq: rabbitmq.clone(),
				webhook: self.worker.webhook.clone(),
			}),

			(true, _, _) => bail!("Worker configuration is missing"),
			_ => bail!("Calling must_worker_config on a non-worker backend"),
		}
	}

	/// Attempt connection to the Postgres database and RabbitMQ. Also populates
	/// the internal `pg_pool` and `channel` fields with the connections.
	pub async fn connect(&mut self) -> Result<(), anyhow::Error> {
		match &self.storage {
			Some(StorageConfig::Postgres(config)) => {
				let storage = PostgresStorage::new(&config.db_url, config.extra.clone())
					.await
					.with_context(|| format!("Connecting to postgres DB {}", config.db_url))?;

				self.storage_adapter = Arc::new(StorageAdapter::Postgres(storage));
			}
			_ => {
				self.storage_adapter = Arc::new(StorageAdapter::Noop);
			}
		}

View on GitHub (pinned to 81da93e8a4)