{"record":{"id":"100ea5a9581c261b","repo":"vectordotdev/vector","slug":"static-regex-always-compiles","errorCode":null,"errorMessage":"static regex always compiles","messagePattern":"static regex always compiles","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/sources/datadog_agent/mod.rs","lineNumber":472,"sourceCode":"            .or_else(|| header.map(Arc::from))\n    }\n}\n\nimpl DatadogAgentSource {\n    pub(crate) fn new(\n        store_api_key: bool,\n        decoder: Decoder,\n        protocol: &'static str,\n        logs_schema_definition: Option<schema::Definition>,\n        log_namespace: LogNamespace,\n        parse_ddtags: bool,\n        split_metric_namespace: bool,\n    ) -> Self {\n        Self {\n            api_key_extractor: ApiKeyExtractor {\n                store_api_key,\n                matcher: Regex::new(r\"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??\")\n                    .expect(\"static regex always compiles\"),\n            },\n            log_schema_host_key: log_schema()\n                .host_key_target_path()\n                .expect(\"global log_schema.host_key to be valid path\")\n                .clone(),\n            log_schema_source_type_key: log_schema()\n                .source_type_key_target_path()\n                .expect(\"global log_schema.source_type_key to be valid path\")\n                .clone(),\n            decoder,\n            protocol,\n            logs_schema_definition: logs_schema_definition.map(Arc::new),\n            log_namespace,\n            events_received: register!(EventsReceived),\n            parse_ddtags,\n            split_metric_namespace,\n        }\n    }","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/vectordotdev/vector/blob/0d4ab78a4f0d9c9e5d03a50108a2ae4d2f4b2460/src/sources/datadog_agent/mod.rs#L454-L490","documentation":"The Datadog Agent source builds an API-key-extracting regex at construction time and calls .expect(\"static regex always compiles\"). Because the pattern is a compile-time constant, this can only panic if the regex crate itself is broken or the constant is edited incorrectly — in normal operation it never fires.","triggerScenarios":"Only reachable when the Datadog Agent source (DatadogAgentConfig::into_source / build) is instantiated and the hard-coded pattern r\"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??\" fails to compile — effectively only after a code edit introduces a syntax error into the literal.","commonSituations":"Developers modifying the regex literal with invalid syntax; dependency upgrades changing regex crate semantics; never in production with unmodified code.","solutions":["If you edited the regex, verify it compiles (e.g. via regex::Regex::new in a test or regex101).","Check for regex crate version regressions in Cargo.lock.","No user action needed — this is an internal invariant."],"exampleFix":"// before\nRegex::new(r\"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??\").expect(\"static regex always compiles\")\n// after (compile-checked at startup with clearer context, e.g. once_cell Lazy + unwrap)\nstatic API_KEY_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r\"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??\").unwrap());","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// No user-side guard possible: the pattern is a hard-coded constant.\n// Ensure in CI: assert!(Regex::new(r\"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??\").is_ok());","tryCatchPattern":null,"preventionTips":["Add a unit test compiling every static regex literal.","Use once_cell/Lazy so failures surface deterministically at startup.","Don't hand-edit the pattern without running regex tests."],"tags":["rust","panic","regex","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0d4ab78a4f0d9c9e5d03a50108a2ae4d2f4b2460","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}