diem/diem · error · Error
Cannot subscribe to zero event keys!
Error message
Cannot subscribe to zero event keys!
What it means
`Error::CannotSubscribeToZeroEventKeys` is thrown by the event-notifications service when a caller attempts to create a subscription with an empty set of event keys. The service requires at least one event key per subscription, so zero keys is rejected immediately as a programming/API misuse error.
Source
Thrown at state-sync/inter-component/event-notifications/src/lib.rs:47
Arc,
},
task::{Context, Poll},
};
use storage_interface::DbReaderWriter;
use thiserror::Error;
#[cfg(test)]
mod tests;
// Maximum channel sizes for each notification subscriber. If messages are not
// consumed, they will be dropped (oldest messages first). The remaining messages
// will be retrieved using FIFO ordering.
const EVENT_NOTIFICATION_CHANNEL_SIZE: usize = 100;
const RECONFIG_NOTIFICATION_CHANNEL_SIZE: usize = 1;
#[derive(Clone, Debug, Deserialize, Error, PartialEq, Serialize)]
pub enum Error {
#[error("Cannot subscribe to zero event keys!")]
CannotSubscribeToZeroEventKeys,
#[error("Missing event subscription! Subscription ID: {0}")]
MissingEventSubscription(u64),
#[error("Unable to send event notification! Error: {0}")]
UnableToSendEventNotification(String),
#[error("Unexpected error encountered: {0}")]
UnexpectedErrorEncountered(String),
}
impl From<SendError> for Error {
fn from(error: SendError) -> Self {
Error::UnableToSendEventNotification(error.to_string())
}
}
/// The interface between state sync and the subscription notification service,
/// allowing state sync to notify the subscription service of new events.
#[async_trait]View on GitHub (pinned to fc4714a8ea)
Solutions
- Ensure the event key list passed to subscribe is non-empty before calling; short-circuit or default-fill empty lists.
- Fix the configuration/filtering logic that produced an empty key set.
- Add an upfront assert/validation on config that at least one event key is configured.
Example fix
// before
subscriptions.subscribe(&event_keys).await?;
// after
if event_keys.is_empty() {
return Err(anyhow!("refusing to subscribe: no event keys configured"));
}
subscriptions.subscribe(&event_keys).await?; Defensive patterns
Strategy: validation
Validate before calling
fn validate_subscription_keys(keys: &[EventKey]) -> Result<(), String> {
if keys.is_empty() {
Err("cannot subscribe to zero event keys; provide at least one key".to_string())
} else {
Ok(())
}
}
// before subscribe: validate_subscription_keys(&keys)?; Type guard
fn has_keys(keys: &[EventKey]) -> bool {
!keys.is_empty()
} Try / catch
match subscriptions.subscribe(&keys).await {
Err(Error::CannotSubscribeToZeroEventKeys) => {
log::error!("subscription request had no event keys; check config/filter");
}
other => other?,
} Prevention
- validate config requires >=1 event key
- beware filters that can empty the key list
- unit-test subscription setup with real config
- fail fast at startup, not at subscribe time
When it happens
Trigger: Calling the subscribe API with an empty events/keys collection (e.g. `&[]`, empty Vec, or a filtered list that ended up empty).
Common situations: Building the subscription list dynamically from config and all keys being filtered out; typos in key names causing an empty intersection; initialization order where the configured keys have not been loaded yet.
Related errors
- Missing event subscription! Subscription ID: {0}
- Unable to send event notification! Error: {0}
- Unexpected error encountered: {0}
- Specified output file path is a directory
- Unable to serialize keys
AI-assisted analysis of diem/diem@fc4714a8ea (2026-09-04).
Data as JSON: /api/errors/7794be5ce8368469.
Report an issue: GitHub.