{"record":{"id":"de6ffb479e4eb024","repo":"block/buzz","slug":"sign-event","errorCode":null,"errorMessage":"sign event","messagePattern":"sign event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/buzz-db/src/runtime/tests.rs","lineNumber":1921,"sourceCode":"    let (comm_b, chan_b) = (Uuid::new_v4(), Uuid::new_v4());\n    for pool in [&writer, &replica] {\n        seed_community_channel(pool, comm_a, chan_a, &author).await;\n        seed_community_channel(pool, comm_b, chan_b, &author).await;\n    }\n\n    // A p-tag mention is what makes a row eligible for the mentions and\n    // needs-action feeds. Kind 9 satisfies mentions + activity;\n    // needs-action admits only approval/reminder kinds, so each\n    // community also gets a kind-46010 row.\n    let mentioned = nostr::Keys::generate();\n    let mentioned_hex = mentioned.public_key().to_hex();\n    let mentioned_bytes = mentioned.public_key().to_bytes();\n    let tagged_kind = |kind: u16, content: &str, secs: u64| {\n        nostr::EventBuilder::new(nostr::Kind::Custom(kind), content)\n            .tags([nostr::Tag::parse([\"p\", mentioned_hex.as_str()]).expect(\"p tag\")])\n            .custom_created_at(nostr::Timestamp::from(secs))\n            .sign_with_keys(&author)\n            .expect(\"sign event\")\n    };\n    let tagged = |content: &str, secs: u64| tagged_kind(9, content, secs);\n\n    let base = 1_700_000_000u64;\n    // Shared rows (both DBs) + replica-only rows (divergence) per community.\n    let a_shared = tagged(\"a-shared\", base);\n    let b_shared = tagged(\"b-shared\", base + 1);\n    for pool in [&writer, &replica] {\n        insert_top_level(pool, comm_a, chan_a, &a_shared).await;\n        insert_mentions(\n            pool,\n            CommunityId::from_uuid(comm_a),\n            &a_shared,\n            Some(chan_a),\n        )\n        .await\n        .expect(\"mentions a-shared\");\n        insert_top_level(pool, comm_b, chan_b, &b_shared).await;","sourceCodeStart":1903,"sourceCodeEnd":1939,"githubUrl":"https://github.com/block/buzz/blob/dad5a33865fc81a2e55b3b60746632f615ec1e3a/crates/buzz-db/src/runtime/tests.rs#L1903-L1939","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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"],"exampleFix":"// before\n.sign_with_keys(&author)\n.expect(\"sign event\")\n// after\nlet event = sign_with_keys(&author).unwrap_or_else(|e| panic!(\"sign event: {e}\"));","handlingStrategy":"validation","validationCode":"let secret = SecretKey::from_hex(hex)?; // fail fast on bad key material before building events\nlet author = Keys::new(secret);\nassert!(!author.public_key().to_bytes().is_empty());","typeGuard":"fn valid_keys(k: &Keys) -> bool { !k.secret_key().display_secret().value().is_empty() }","tryCatchPattern":"let ev = builder.sign_with_keys(&author)\n    .map_err(|e| TestSetupError::Sign(e.to_string()))?;","preventionTips":["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"],"tags":["nostr","test-setup","panic","signing"],"backgroundTag":"expect-panic-on-result","analyzedSha":"dad5a33865fc81a2e55b3b60746632f615ec1e3a","analyzedAt":"2026-08-30T13:49:18.474Z","contentChangedAt":"2026-08-30T13:49:18.474Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}