block/buzz · error
database URL has path segment
Error message
database URL has path segment
What it means
The test derives the scratch database URL by finding the last '/' in the admin URL with rfind('/') and expects a path segment (e.g. .../postgres) to strip and replace with the scratch name. The expect panics when the URL contains no '/' after the scheme section, i.e. the admin URL has no database path component, so splitting cannot produce a valid sibling URL.
Source
Thrown at crates/buzz-db/src/store/channel_members.rs:3135
}
#[tokio::test]
#[ignore = "requires Postgres"]
async fn desired_schema_rejects_stale_legacy_roster_role() {
use nostr::{EventBuilder, Keys, Kind, Tag, Timestamp};
let admin = PgPool::connect(&admin_url().await)
.await
.expect("connect admin");
let scratch_name = format!("schema_roster_role_{}", Uuid::new_v4().simple());
sqlx::query(sqlx::AssertSqlSafe(format!(
"CREATE DATABASE {scratch_name}"
)))
.execute(&admin)
.await
.expect("create desired-schema scratch db");
let base_url = admin_url().await;
let slash = base_url.rfind('/').expect("database URL has path segment");
let scratch_url = format!("{}/{}", &base_url[..slash], scratch_name);
let pool = PgPoolOptions::new()
.max_connections(1)
.connect(&scratch_url)
.await
.expect("connect desired-schema scratch db");
sqlx::raw_sql(include_str!("../../../../schema/schema.sql"))
.execute(&pool)
.await
.expect("apply desired-state schema");
let db = Db::from_pool(pool.clone());
let community_uuid = Uuid::new_v4();
let community = CommunityId::from_uuid(community_uuid);
let channel = Uuid::new_v4();
let relay_keys = Keys::generate();
let owner_keys = Keys::generate();
let owner = owner_keys.public_key().to_bytes();View on GitHub (pinned to dad5a33865)
Solutions
- Set the admin DATABASE_URL to include a database path, e.g. postgres://user:pass@localhost:5432/postgres
- Validate the URL with Url::parse and use url.set_path(scratch_name) instead of string rfind slicing
- Log/redact the admin_url before running to confirm it has a path segment
- If using a unix socket URL, restructure with the Url builder rather than rfind
Example fix
// before
let slash = base_url.rfind('/').expect("database URL has path segment");
let scratch_url = format!("{}/{}", &base_url[..slash], scratch_name);
// after
let mut url = url::Url::parse(&base_url).expect("admin URL parses");
if url.path() == "" || url.path() == "/" { panic!("admin URL lacks database path segment: {base_url}"); }
url.set_path(&scratch_name);
let scratch_url = url.to_string(); Defensive patterns
Strategy: validation
Validate before calling
let url = url::Url::parse(&base_url)?;
if url.path().is_empty() || url.path() == "/" { panic!("admin URL missing database path segment: {base_url}"); } Type guard
fn has_db_path(u: &str) -> bool {
url::Url::parse(u).map(|p| p.path().len() > 1).unwrap_or(false)
} Prevention
- Always include /postgres (or a real db name) in admin DATABASE_URLs
- Use url::Url::set_path instead of string rfind slicing
- Validate env URLs at startup, not mid-test
When it happens
Trigger: admin_url() returns a URL like postgres://user:pass@host:5432 (no trailing /postgres), an empty string, or a malformed URL without a path segment — then rfind('/') still matches the scheme's '//' but yields a prefix like 'postgres:' producing a broken scratch URL, or None-equivalent outcomes.
Common situations: .env DATABASE_URL missing the /postgres database name; someone trimmed the URL for logging; URL written as postgres://host only; URL is postgresql:/// (empty db) or uses a unix socket form the naive rfind split mishandles.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- invalid relay URL {raw:?}: {error}
- Configuration error: {e}
- git pack cache path must be available
- BUZZ_RELAY_PRIVATE_KEY must be set when BUZZ_REQUIRE_AUTH_TO
- --host must not be empty
AI-assisted analysis of block/buzz@dad5a33865 (2026-08-30).
Data as JSON: /api/errors/cb986c87173ae59a.
Report an issue: GitHub.