{"record":{"id":"9fff5b92188b8daf","repo":"vectordotdev/vector","slug":"static-non-zero-number","errorCode":null,"errorMessage":"static non-zero number","messagePattern":"static non-zero number","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/transforms/dedupe/common.rs","lineNumber":34,"sourceCode":"\n/// Configuration for time based cache.\n#[serde_as]\n#[configurable_component]\n#[derive(Clone, Debug)]\n#[serde(deny_unknown_fields)]\npub struct TimedCacheConfig {\n    /// Maximum age of items in deduplication cache, before duplicates are allowed again.\n    #[serde_as(as = \"serde_with::DurationMilliSeconds<u64>\")]\n    pub max_age_ms: Duration,\n\n    /// Set to true if dropped duplicates should refresh the age timer.\n    #[serde(default = \"crate::serde::default_false\")]\n    pub refresh_on_drop: bool,\n}\n\npub const fn default_cache_config() -> CacheConfig {\n    CacheConfig {\n        num_events: NonZeroUsize::new(5000).expect(\"static non-zero number\"),\n    }\n}\n\n/// Options to control what fields to match against.\n///\n/// When no field matching configuration is specified, events are matched using the `timestamp`,\n/// `host`, and `message` fields from an event. The specific field names used are those set in\n/// the global [`log schema`][global_log_schema] configuration.\n///\n/// [global_log_schema]: https://vector.dev/docs/reference/configuration/global-options/#log_schema\n// TODO: This enum renders correctly in terms of providing equivalent Cue output when using the\n// machine-generated stuff vs the previously-hand-written Cue... but what it _doesn't_ have in the\n// machine-generated output is any sort of blurb that these \"fields\" (`match` and `ignore`) are\n// actually mutually exclusive.\n//\n// We know that to be the case when we're generating the output from the configuration schema, so we\n// need to emit something in that output to indicate as much, and further, actually use it on the\n// Cue side to add some sort of boilerplate about them being mutually exclusive, etc.","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/transforms/dedupe/common.rs#L16-L52","documentation":"default_cache_config for the dedupe transform builds a CacheConfig whose num_events is NonZeroUsize::new(5000).expect(\"static non-zero number\"). Because 5000 is a compile-time constant that is provably non-zero, this expect can never fire; it exists only to satisfy NonZeroUsize's fallible constructor inside a const fn. It is a compile-time invariant marker, not a runtime risk.","triggerScenarios":"Not triggerable at runtime: it is evaluated only when producing the default CacheConfig (serde default for the dedupe cache), and the literal 5000 guarantees success.","commonSituations":"Developers reading the code may mistake it for a live panic path; it only becomes reachable if someone edits the literal 5000 to 0 (which would then panic whenever defaults are constructed, e.g. an omitting `cache: true` in dedupe config).","solutions":["No action needed; the constant is valid and the expect is unreachable.","If modifying this code, keep the literal non-zero (or switch to a const assertion) so the expect remains untriggerable.","Never change the literal to 0; use Option<NonZeroUsize> with a default if you need a 'no limit' case."],"exampleFix":"// before\nnum_events: NonZeroUsize::new(5000).expect(\"static non-zero number\"),\n// after (equivalent, no behavior change needed)\nnum_events: NonZeroUsize::new(5000).expect(\"static non-zero number\"), // keep; 5000 != 0 by construction","handlingStrategy":"validation","validationCode":"assert!(5000 > 0); // constant is provably non-zero; no runtime guard needed","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never edit the literal to 0; NonZeroUsize exists to forbid that.","Keep such defaults in const fns so invalid literals are caught by expect at first use.","Review any change to CacheConfig defaults carefully."],"tags":["rust","const-fn","nonzero","dedupe-transform","default-value"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}