Skip to content

Commit b2d2863

Browse files
committed
Improve pseudo-class error message
When encountering a pseudo-class that is unrecognized, we should not state it is "unsupported" a it may be entirely invalid. While there are some pseudo-classes that are valid but not supported, the status of such things can change all the time and our internal list may become outdated. Additionally, sometimes users trying to incorrectly specify tags with namespaces can trigger this message as they may assume that because a namespace is declared in their document as `ns:element` that they can do this in CSS as well. This specific case is not easily detectable for us as we generically parse the syntax, not the intent of the syntax. To clear up confusion, be more specific and simply state that anytime a pseudo-class is not recognized by soupsieve that it is either invalid or not recognizable by soupsieve. By stating both possibilities, this points out that pseudo-class syntax was noted and that it is unrecognized by soupsieve, regardless of status, and may be entirely invalid. Additionally, note that if it being recognized as a pseudo-class is a surprise that the colon can be escaped to avoid the recognition as such.
1 parent c811bdf commit b2d2863

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

docs/src/markdown/about/changelog.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## 2.6
44

5-
- **NEW** Add support for `&` as scoping root per the CSS Nesting Module, Level 1. When `&` is used outside the
5+
- **NEW**: Add support for `&` as scoping root per the CSS Nesting Module, Level 1. When `&` is used outside the
66
context of nesting, it is treated as the scoping root (equivalent to `:scope`).
7+
- **FIX**: Improve error message when an unrecognized pseudo-class is used.
78

89
## 2.5
910

soupsieve/css_parser.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,9 @@ def parse_pseudo_class(
655655
m.start(0)
656656
)
657657
else:
658-
raise NotImplementedError(
659-
f"'{pseudo}' pseudo-class is not implemented at this time"
658+
raise ValueError(
659+
f"'{pseudo}' was detected as a pseudo-class and is either unsupported or invalid. "
660+
"If the syntax was not intended to be recognized as a pseudo-class, please escape the colon."
660661
)
661662

662663
return has_selector, is_html

0 commit comments

Comments
 (0)