{"record":{"id":"51c2c7daec1c076d","repo":"astral-sh/ruff","slug":"invalid-default-warning-pattern","errorCode":null,"errorMessage":"invalid default warning pattern","messagePattern":"invalid default warning pattern","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/flake8_pytest_style/settings.rs","lineNumber":29,"sourceCode":"use super::types;\n\npub fn default_broad_exceptions() -> Vec<IdentifierPattern> {\n    [\n        \"BaseException\",\n        \"Exception\",\n        \"ValueError\",\n        \"OSError\",\n        \"IOError\",\n        \"EnvironmentError\",\n        \"socket.error\",\n    ]\n    .map(|pattern| IdentifierPattern::new(pattern).expect(\"invalid default exception pattern\"))\n    .to_vec()\n}\n\npub fn default_broad_warnings() -> Vec<IdentifierPattern> {\n    [\"Warning\", \"UserWarning\", \"DeprecationWarning\"]\n        .map(|pattern| IdentifierPattern::new(pattern).expect(\"invalid default warning pattern\"))\n        .to_vec()\n}\n\n#[derive(Debug, Clone, CacheKey)]\npub struct Settings {\n    pub fixture_parentheses: bool,\n    pub parametrize_names_type: types::ParametrizeNameType,\n    pub parametrize_values_type: types::ParametrizeValuesType,\n    pub parametrize_values_row_type: types::ParametrizeValuesRowType,\n    pub raises_require_match_for: Vec<IdentifierPattern>,\n    pub raises_extend_require_match_for: Vec<IdentifierPattern>,\n    pub mark_parentheses: bool,\n    pub warns_require_match_for: Vec<IdentifierPattern>,\n    pub warns_extend_require_match_for: Vec<IdentifierPattern>,\n}\n\nimpl Default for Settings {\n    fn default() -> Self {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/flake8_pytest_style/settings.rs#L11-L47","documentation":"This is a compile-time-fixed default-value construction in flake8_pytest_style's settings. `default_broad_warnings` builds IdentifierPattern values from a hard-coded list (\"Warning\", \"UserWarning\", \"DeprecationWarning\") and calls `.expect(...)`. IdentifierPattern::new only fails for patterns that cannot be parsed/compiled; since these literals are valid, the panic is an internal invariant check and only fires if a refactor makes the defaults invalid.","triggerScenarios":"It cannot be triggered by user configuration: the inputs are hard-coded. It would only panic if a code change introduces an unparseable default pattern or changes IdentifierPattern::new's validation to reject these strings (e.g. disallowing bare names).","commonSituations":"Developers hit this while modifying ruff's flake8_pytest_style settings — e.g. adding a new default warning pattern with a typo, or tightening IdentifierPattern parsing so plain identifiers are rejected.","solutions":["Fix the hard-coded default list so every entry is a valid IdentifierPattern (valid identifier, correct case)","Re-run the settings/default tests after changing IdentifierPattern::new validation","If defaults must support arbitrary patterns, use lazy_static/OnceLock with proper error handling instead of expect"],"exampleFix":"// before\n[\"Warning\", \"UserWarnig\", \"DeprecationWarning\"]\n    .map(|p| IdentifierPattern::new(p).expect(\"invalid default warning pattern\"))\n// after\n[\"Warning\", \"UserWarning\", \"DeprecationWarning\"]\n    .map(|p| IdentifierPattern::new(p).expect(\"invalid default warning pattern\"))","handlingStrategy":"validation","validationCode":"// In ruff's repo: verify defaults parse before shipping\nfor pattern in [\"Warning\", \"UserWarning\", \"DeprecationWarning\"] {\n    IdentifierPattern::new(pattern).unwrap_or_else(|e| panic!(\"bad default {pattern}: {e}\"));\n}","typeGuard":"fn valid_pattern(p: &str) -> bool { IdentifierPattern::new(p).is_ok() }","tryCatchPattern":null,"preventionTips":["Add a unit test that constructs all default settings without panicking","Keep default literal lists next to their validation and review them together","Run cargo test after any change to IdentifierPattern validation"],"tags":["rust","panic","configuration","flake8-pytest-style"],"backgroundTag":"invalid-default-constant","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}