{"record":{"id":"7794be5ce8368469","repo":"diem/diem","slug":"cannot-subscribe-to-zero-event-keys","errorCode":null,"errorMessage":"Cannot subscribe to zero event keys!","messagePattern":"Cannot subscribe to zero event keys!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"state-sync/inter-component/event-notifications/src/lib.rs","lineNumber":47,"sourceCode":"        Arc,\n    },\n    task::{Context, Poll},\n};\nuse storage_interface::DbReaderWriter;\nuse thiserror::Error;\n\n#[cfg(test)]\nmod tests;\n\n// Maximum channel sizes for each notification subscriber. If messages are not\n// consumed, they will be dropped (oldest messages first). The remaining messages\n// will be retrieved using FIFO ordering.\nconst EVENT_NOTIFICATION_CHANNEL_SIZE: usize = 100;\nconst RECONFIG_NOTIFICATION_CHANNEL_SIZE: usize = 1;\n\n#[derive(Clone, Debug, Deserialize, Error, PartialEq, Serialize)]\npub enum Error {\n    #[error(\"Cannot subscribe to zero event keys!\")]\n    CannotSubscribeToZeroEventKeys,\n    #[error(\"Missing event subscription! Subscription ID: {0}\")]\n    MissingEventSubscription(u64),\n    #[error(\"Unable to send event notification! Error: {0}\")]\n    UnableToSendEventNotification(String),\n    #[error(\"Unexpected error encountered: {0}\")]\n    UnexpectedErrorEncountered(String),\n}\n\nimpl From<SendError> for Error {\n    fn from(error: SendError) -> Self {\n        Error::UnableToSendEventNotification(error.to_string())\n    }\n}\n\n/// The interface between state sync and the subscription notification service,\n/// allowing state sync to notify the subscription service of new events.\n#[async_trait]","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/diem/diem/blob/fc4714a8ea273b6efe8b13dbce72ea60aad9a16c/state-sync/inter-component/event-notifications/src/lib.rs#L29-L65","documentation":"`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.","triggerScenarios":"Calling the subscribe API with an empty events/keys collection (e.g. `&[]`, empty Vec, or a filtered list that ended up empty).","commonSituations":"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.","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."],"exampleFix":"// before\nsubscriptions.subscribe(&event_keys).await?;\n// after\nif event_keys.is_empty() {\n    return Err(anyhow!(\"refusing to subscribe: no event keys configured\"));\n}\nsubscriptions.subscribe(&event_keys).await?;","handlingStrategy":"validation","validationCode":"fn validate_subscription_keys(keys: &[EventKey]) -> Result<(), String> {\n    if keys.is_empty() {\n        Err(\"cannot subscribe to zero event keys; provide at least one key\".to_string())\n    } else {\n        Ok(())\n    }\n}\n// before subscribe: validate_subscription_keys(&keys)?;","typeGuard":"fn has_keys(keys: &[EventKey]) -> bool {\n    !keys.is_empty()\n}","tryCatchPattern":"match subscriptions.subscribe(&keys).await {\n    Err(Error::CannotSubscribeToZeroEventKeys) => {\n        log::error!(\"subscription request had no event keys; check config/filter\");\n    }\n    other => other?,\n}","preventionTips":["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"],"tags":["rust","state-sync","events","validation","subscription"],"backgroundTag":"empty-subscription-keys","analyzedSha":"fc4714a8ea273b6efe8b13dbce72ea60aad9a16c","analyzedAt":"2026-09-04T21:07:05.890Z","contentChangedAt":"2026-09-04T21:07:05.890Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}