{"record":{"id":"e5540be29e478441","repo":"reacherhq/check-if-email-exists","slug":"calling-must-worker-config-on-a-non-worker-backend","errorCode":null,"errorMessage":"Calling must_worker_config on a non-worker backend","messagePattern":"Calling must_worker_config on a non-worker backend","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"backend/src/config.rs","lineNumber":185,"sourceCode":"\t\t\teverything_else: EverythingElseVerifMethod::Smtp(default_smtp_config),\n\t\t}\n\t}\n\n\t/// Get the worker configuration.\n\t///\n\t/// # Panics\n\t///\n\t/// Panics if the worker configuration is missing.\n\tpub fn must_worker_config(&self) -> Result<MustWorkerConfig, anyhow::Error> {\n\t\tmatch (self.worker.enable, &self.worker.rabbitmq, &self.channel) {\n\t\t\t(true, Some(rabbitmq), Some(channel)) => Ok(MustWorkerConfig {\n\t\t\t\tchannel: channel.clone(),\n\t\t\t\trabbitmq: rabbitmq.clone(),\n\t\t\t\twebhook: self.worker.webhook.clone(),\n\t\t\t}),\n\n\t\t\t(true, _, _) => bail!(\"Worker configuration is missing\"),\n\t\t\t_ => bail!(\"Calling must_worker_config on a non-worker backend\"),\n\t\t}\n\t}\n\n\t/// Attempt connection to the Postgres database and RabbitMQ. Also populates\n\t/// the internal `pg_pool` and `channel` fields with the connections.\n\tpub async fn connect(&mut self) -> Result<(), anyhow::Error> {\n\t\tmatch &self.storage {\n\t\t\tSome(StorageConfig::Postgres(config)) => {\n\t\t\t\tlet storage = PostgresStorage::new(&config.db_url, config.extra.clone())\n\t\t\t\t\t.await\n\t\t\t\t\t.with_context(|| format!(\"Connecting to postgres DB {}\", config.db_url))?;\n\n\t\t\t\tself.storage_adapter = Arc::new(StorageAdapter::Postgres(storage));\n\t\t\t}\n\t\t\t_ => {\n\t\t\t\tself.storage_adapter = Arc::new(StorageAdapter::Noop);\n\t\t\t}\n\t\t}","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/reacherhq/check-if-email-exists/blob/81da93e8a419f601c05e1bcf4a197d25eb0e349d/backend/src/config.rs#L167-L203","documentation":"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'.","triggerScenarios":"Calling backend.must_worker_config() when worker.enable is false or the worker section is absent in BackendConfig.","commonSituations":"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.","solutions":["Only call must_worker_config when config.worker.enable is true","Check backend config mode before requesting the worker config","If the backend should be a worker, set worker.enable = true in the config"],"exampleFix":"// before\nlet must_worker = backend.must_worker_config().await?;\n// after\nif backend.config.worker.enable {\n    let must_worker = backend.must_worker_config().await?;\n}","handlingStrategy":"type-guard","validationCode":"if !config.worker.enable {\n    eprintln!(\"must_worker_config requires worker.enable = true\");\n}","typeGuard":"fn is_worker_backend(config: &BackendConfig) -> bool { config.worker.enable }","tryCatchPattern":"match backend.must_worker_config().await {\n    Err(e) if e.to_string().contains(\"non-worker backend\") => {\n        eprintln!(\"Not a worker backend; skip worker setup\");\n    }\n    Err(e) => return Err(e),\n    Ok(cfg) => cfg,\n}","preventionTips":["Gate worker setup code behind config.worker.enable checks","Keep one config flag per deployment role (API vs worker)","Avoid calling role-specific accessors from shared startup code"],"tags":["config","worker","misuse","invalid-state"],"backgroundTag":"unsupported-operation","analyzedSha":"81da93e8a419f601c05e1bcf4a197d25eb0e349d","analyzedAt":"2026-09-11T10:06:14.663Z","contentChangedAt":"2026-09-11T10:06:14.663Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}