block/buzz · error · anyhow::Error

failed to build setup nudge: {e}

Error message

failed to build setup nudge: {e}

What it means

publish_setup_nudge builds and signs a Nostr event for the setup nudge via the SDK event builder. If the builder fails (map_err on the build result), it wraps the cause as 'failed to build setup nudge: {e}'. nudge_authorized_event propagates this to the caller as an anyhow error.

Source

Thrown at crates/buzz-acp/src/setup_mode.rs:674

        // Top-level event: reply to the triggering event.
        Some(ThreadRef {
            root_event_id: triggering_event.id,
            parent_event_id: triggering_event.id,
        })
    };

    let body = payload.nudge_body();

    let event_builder = buzz_sdk::build_message(
        channel_id,
        &body,
        thread_ref.as_ref(),
        &[recipient_hex], // p-tag the verified effective asker
        false,
        &[],
        &[],
    )
    .map_err(|e| anyhow::anyhow!("failed to build setup nudge: {e}"))?;

    let signed = event_builder
        .sign_with_keys(keys)
        .map_err(|e| anyhow::anyhow!("failed to sign setup nudge: {e}"))?;

    publisher
        .publish_event(signed)
        .await
        .map_err(|e| anyhow::anyhow!("failed to publish setup nudge: {e}"))?;

    Ok(())
}

// ── Tests ─────────────────────────────────────────────────────────────────────

#[cfg(test)]
mod tests {
    use super::*;

View on GitHub (pinned to dad5a33865)

Solutions

  1. Log and inspect the wrapped cause `{e}` — it names the exact builder failure
  2. Validate the recipient pubkey is 64-char lowercase hex before building the event
  3. Check the event builder call matches the current buzz-sdk EventBuilder API after upgrades
  4. Return a typed error to the caller instead of relying on anyhow string context

Example fix

// before
.map_err(|e| anyhow::anyhow!("failed to build setup nudge: {e}"))?;
// after
let pubkey = secp256k1::XOnlyPublicKey::from_str(&recipient_hex)
    .context("invalid recipient pubkey for setup nudge")?;
// ... then build with the parsed key
Defensive patterns

Strategy: validation

Validate before calling

fn valid_pubkey_hex(s: &str) -> bool {
    s.len() == 64 && s.bytes().all(|b| b.is_ascii_hexdigit())
}
// call before building the nudge event
if !valid_pubkey_hex(&recipient_hex) { bail!("bad recipient pubkey"); }

Type guard

null

Try / catch

match publish_setup_nudge(...).await {
    Ok(_) => {},
    Err(e) => tracing::error!(error = ?e, "setup nudge publish failed"),
} // inspect the wrapped builder cause in logs

Prevention

When it happens

Trigger: The buzz-sdk event builder returns an error while constructing the nudge event — invalid tag inputs (e.g. malformed recipient pubkey hex), or builder validation failures for kind/content constraints.

Common situations: Upstream produced a recipient pubkey that is not valid hex or wrong length; a refactor changed the builder signature/tag expectations; SDK version change tightened event validation.

Related errors


AI-assisted analysis of block/buzz@dad5a33865 (2026-09-05). Data as JSON: /api/errors/36e645b671d31398. Report an issue: GitHub.