moghtech/komodo · critical · anyhow::Error
'config.database' not configured correctly. must pass…
Error message
'config.database' not configured correctly. must pass either 'config.database.uri', or 'config.database.address' + 'config.database.username' + 'config.database.password'
What it means
The database init() builds a mongodb Client options object from config.database and validates that exactly one of the accepted credential shapes is present: a full URI, or an address together with username+password. Any other combination falls to the catch-all arm and aborts initialization with this error, because the driver cannot construct valid connection options.
Solutions
- Set config.database.uri to a valid mongodb:// connection string (simplest path)
- Or set address together with BOTH username and password in config.database
- Log the resolved config keys (without secrets) to see which fields are missing
- Validate the database config at application startup before calling new()
Example fix
// before (config) [database] address = "localhost:27017" // after (config) [database] uri = "mongodb://localhost:27017" # or address + username + password together
Defensive patterns
Strategy: validation
Validate before calling
fn validate_db_config(cfg: &DatabaseConfig) -> Result<(), String> {
if cfg.uri.is_some() { return Ok(()); }
if cfg.address.is_some() && cfg.username.is_some() && cfg.password.is_some() { return Ok(()); }
Err("config.database needs 'uri' or 'address' + 'username' + 'password'".into())
} Try / catch
match Database::new(&config).await {
Err(e) if e.to_string().contains("'config.database' not configured correctly") => {
panic!("database section misconfigured: {}", e);
}
other => other,
} Prevention
- Fail fast at startup by validating the database config before use
- Keep all four fields (or just uri) sourced from env/config together
- Add an integration test that constructs Database from your production config shape
- Never commit partial example configs as defaults
When it happens
Trigger: Calling Database::new when config.database has neither uri, nor address, nor the username/password pair; e.g. only address without username/password, or username/password without address, or an entirely empty database section.
Common situations: Partial config files where only database.address was set; env-var-driven configs where some DB_* variables weren't exported; switching from URI-based to split-credential config and forgetting a field; default/example configs left unedited.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
AI-assisted analysis of moghtech/komodo@780ac68b99 (2026-09-08).
Data as JSON: /api/errors/e4ebfae76428908c.
Report an issue: GitHub.
Appendix: source
Thrown at lib/database/src/lib.rs:231
!uri.is_empty(),
!address.is_empty(),
!username.is_empty(),
!password.is_empty(),
) {
(true, _, _, _) => {
client = client.uri(uri);
}
(_, true, true, true) => {
client = client
.address(address)
.username(username)
.password(password);
}
(_, true, _, _) => {
client = client.address(address);
}
_ => {
return Err(anyhow!(
"'config.database' not configured correctly. must pass either 'config.database.uri', or 'config.database.address' + 'config.database.username' + 'config.database.password'"
));
}
}
let client = client
.build()
.await
.context("Failed to initialize database connection.")?;
Ok(client.database(db_name))
}
async fn resource_collection<T: Send + Sync>(
db: &Database,
collection_name: &str,
) -> anyhow::Result<Collection<T>> {
let coll = db.collection::<T>(collection_name);View on GitHub (pinned to 780ac68b99)