{"record":{"id":"8bc247e8c31e665e","repo":"astral-sh/ruff","slug":"invalid-default-exception-pattern","errorCode":null,"errorMessage":"invalid default exception pattern","messagePattern":"invalid default exception pattern","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/ruff_linter/src/rules/flake8_pytest_style/settings.rs","lineNumber":23,"sourceCode":"\nuse crate::display_settings;\nuse ruff_macros::CacheKey;\n\nuse crate::settings::types::IdentifierPattern;\n\nuse 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,","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/flake8_pytest_style/settings.rs#L5-L41","documentation":"flake8-pytest-style builds its default lists of broad-exception patterns for PT001/PT011-style settings from hard-coded names like `ValueError` and `socket.error`. `IdentifierPattern::new` validates each name; the built-in defaults are expected to always be valid, so failure panics — meaning the pattern grammar or defaults were changed inconsistently.","triggerScenarios":"Constructing `Flake8PytestStyleSettings::default` (via `default_broad_exceptions`) when `IdentifierPattern::new` rejects one of the hard-coded defaults (e.g. `socket.error`) — only after a change to the pattern grammar/validator, or if user settings substitute an invalid pattern into the same construction path.","commonSituations":"Contributors editing the defaults or IdentifierPattern validation; users with custom `flake8-pytest-style.broad-exceptions` config passing invalid patterns may see analogous validation errors rather than this specific default panic.","solutions":["If developing: verify which default failed validation and fix the pattern grammar or default list to agree","Update Ruff to a version with consistent defaults/validator","For user-facing config errors, pass valid dotted names (e.g. `socket.error`) in `broad-exceptions`/`broad-exceptions-warn` settings","Temporarily override the settings with your own explicit pattern list in pyproject.toml"],"exampleFix":"// before\n.map(|pattern| IdentifierPattern::new(pattern).expect(\"invalid default exception pattern\"))\n// after\n.map(|pattern| IdentifierPattern::new(pattern))\n.collect::<Result<Vec<_>, _>>()\n.expect(\"built-in default exception patterns must be valid — report this bug\")","handlingStrategy":"validation","validationCode":"# validate user-configured broad exception patterns early\n# ruff config (pyproject.toml): [tool.ruff.lint.flake8-pytest-style]\n# broad-exceptions = [\"BaseException\"]  — use valid dotted names, no wildcards\nimport tomllib\ncfg = tomllib.load(open('pyproject.toml','rb'))['tool']['ruff']['lint']['flake8-pytest-style']\nfor p in cfg.get('broad-exceptions', []):\n    assert all(part.isidentifier() for part in p.split('.')), f'invalid pattern: {p}'","typeGuard":"def is_valid_exception_pattern(p: str) -> bool:\n    return bool(p) and all(part.isidentifier() for part in p.split('.'))","tryCatchPattern":null,"preventionTips":["Keep broad-exceptions entries as valid dotted identifiers (e.g. socket.error)","Pin Ruff versions in CI so default-setting changes are explicit","After upgrading Ruff, run a smoke `ruff check` on a pytest file to surface setting changes early"],"tags":["rust","panic","flake8-pytest-style","settings","default-config"],"backgroundTag":"invalid-default-configuration","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"}