block/buzz · error
sign event
Error message
sign event
What it means
This is a panic from `.expect("sign event")` on the Result of `sign_with_keys(&author)` when building a Nostr test event in the community-routing test. The nostr crate returns Err if the secret key is invalid or signing fails; the test deliberately unwraps. It indicates event construction could not produce a signed event.
Source
Thrown at crates/buzz-db/src/runtime/tests.rs:1921
let (comm_b, chan_b) = (Uuid::new_v4(), Uuid::new_v4());
for pool in [&writer, &replica] {
seed_community_channel(pool, comm_a, chan_a, &author).await;
seed_community_channel(pool, comm_b, chan_b, &author).await;
}
// A p-tag mention is what makes a row eligible for the mentions and
// needs-action feeds. Kind 9 satisfies mentions + activity;
// needs-action admits only approval/reminder kinds, so each
// community also gets a kind-46010 row.
let mentioned = nostr::Keys::generate();
let mentioned_hex = mentioned.public_key().to_hex();
let mentioned_bytes = mentioned.public_key().to_bytes();
let tagged_kind = |kind: u16, content: &str, secs: u64| {
nostr::EventBuilder::new(nostr::Kind::Custom(kind), content)
.tags([nostr::Tag::parse(["p", mentioned_hex.as_str()]).expect("p tag")])
.custom_created_at(nostr::Timestamp::from(secs))
.sign_with_keys(&author)
.expect("sign event")
};
let tagged = |content: &str, secs: u64| tagged_kind(9, content, secs);
let base = 1_700_000_000u64;
// Shared rows (both DBs) + replica-only rows (divergence) per community.
let a_shared = tagged("a-shared", base);
let b_shared = tagged("b-shared", base + 1);
for pool in [&writer, &replica] {
insert_top_level(pool, comm_a, chan_a, &a_shared).await;
insert_mentions(
pool,
CommunityId::from_uuid(comm_a),
&a_shared,
Some(chan_a),
)
.await
.expect("mentions a-shared");
insert_top_level(pool, comm_b, chan_b, &b_shared).await;View on GitHub (pinned to dad5a33865)
Solutions
- Verify `author`'s SecretKey is valid (parsed from correct 32-byte hex) before signing
- Check the nostr crate version in Cargo.toml matches the API used (`sign_with_keys` returning Result<Event, Error>)
- Run `cargo update -p nostr` carefully / pin the version; rebuild after dependency changes
Example fix
// before
.sign_with_keys(&author)
.expect("sign event")
// after
let event = sign_with_keys(&author).unwrap_or_else(|e| panic!("sign event: {e}")); Defensive patterns
Strategy: validation
Validate before calling
let secret = SecretKey::from_hex(hex)?; // fail fast on bad key material before building events let author = Keys::new(secret); assert!(!author.public_key().to_bytes().is_empty());
Type guard
fn valid_keys(k: &Keys) -> bool { !k.secret_key().display_secret().value().is_empty() } Try / catch
let ev = builder.sign_with_keys(&author)
.map_err(|e| TestSetupError::Sign(e.to_string()))?; Prevention
- Parse the SecretKey once in a shared fixture and assert validity
- Pin the nostr crate version and review its changelog on upgrade
- Replace bare .expect with context-rich unwrap_or_else panics
When it happens
Trigger: Calling `EventBuilder::sign_with_keys` with a malformed/zeroized secret key, or an incompatible nostr crate version whose sign_with_keys signature/error changed, during setup of `routed_reads_are_confined_to_the_requested_community`.
Common situations: Secret key parsed from bad hex, nostr crate version bump changing the API, refactoring the closure to use a different key type without updating key parsing.
Related errors
- invalid URL {url:?}: {e}
- failed to sign moderation notice: {e}
- BUZZ_RELAY_PRIVATE_KEY must be set when BUZZ_REQUIRE_AUTH_TO
- failed to sign system message: {e}
- failed to sign member snapshot: {error}
AI-assisted analysis of block/buzz@dad5a33865 (2026-08-30).
Data as JSON: /api/errors/de6ffb479e4eb024.
Report an issue: GitHub.