Repository navigation
fix(web): report a selector the engine cannot parse as INVALID_LOCATOR - #2121
okwasniewski merged 1 commit into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
e5879b9 to
ca58a2a
Compare
|
All four inline threads are addressed and resolved: the XPath and regex forms now have tests with the messages Playwright 1.65.1 emits, the selector check runs before the stale and unactionable branches, the raw cause is attached, and the changeset says exit 1. |
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-checked ca58a2a (amended after our first read of e5879b9) against main e486fbd, using real Playwright 1.65.1 messages for each selector form in #2040.
Every code ask from the first read is done:
- The parse check now runs first in
staleOrandclassifyActionError, sodiv:has-text("not found"no longer becomes a retryableNODE_STALE, andnot editableno longer becomesNOT_ACTIONABLE. Both cases have tests. xpath=//[andtext=/(/are now matched by their real messages, with a test for each, so the docs row and the changeset are accurate.- The changeset says exit 1.
{ cause }is kept intranslatePwErrorandclassifyActionError, and dropped for sensitive fills.
Hold: maintainer decision. Classifying Playwright errors by message text was the open question in #2040, and it is still unanswered. Playwright throws a plain Error for all of these and exposes no code or public parser, so on the current driver text is the only signal. The WebDriver BiDi driver (#1503) deletes support.ts and reports this case from structured data (pageParts refuses unknown engines, the in-page query returns unparsedSelector). So this PR only matters until #1503 lands.
Should fix
packages/web/src/support.ts:389Invalid regular expressionandis not a valid XPath expressionare generic browser/JS messages. Today they only reach this pattern through engine calls (evaluate has its own path), so the risk is small. Still, matching thelocator.call prefix Playwright puts on them would keep a future caller from turning an unrelated error intoINVALID_LOCATOR.Unknown engine "is redundant: Playwright's unknown-engine message already containswhile parsing selector.
Nits
- The changeset has no trailing newline.
Verified at e5879b9: vitest run tests/unit/errors.test.ts tests/unit/actions.test.ts passes, and a mutant (isSelectorParseError returns false) fails both new tests. The real messages for every #2040 form went through staleOr, translatePwError and classifyActionError. The delta to ca58a2a adds exactly the ordering, phrases, tests and cause asked for.
There was a problem hiding this comment.
0 issues found across 5 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
Playwright parses a selector lazily, so a malformed CSS selector, a bad xpath=/text=, a stray >>, or an unknown engine name surfaced through translatePwError as an infrastructure ENGINE_FAILURE (exit 3), and an agent read it as retryable infrastructure instead of a test-code typo. The shared translator and the action classifier now recognise Playwright's parse failure and return INVALID_LOCATOR (test, exit 2). Closes e2e-inc#2040
ca58a2a to
b9a183b
Compare
|
@okwasniewski both should-fixes are in at b9a183b: the generic |
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-checked b9a183b: both should-fixes are done. The XPath and regex phrases now only match behind Playwright's locator.<call>: prefix (LOCATOR_EXPRESSION_PARSE_PATTERN), with tests, and the redundant Unknown engine " alternative is gone. The changeset has its trailing newline. No code asks left.
The one red check (test (24), packages/moli "stops descendants when the wrapper exits before release") is an unrelated process-teardown flake, rerun.
Still held on the #2040 maintainer decision: accept message matching until #1503's structured unparsedSelector path replaces it, or close as superseded by #1503.
What
A selector the engine cannot parse now fails as
INVALID_LOCATOR(categorytest, exit 1), throughlocate,count(), an action, orexpect(...), instead ofENGINE_FAILURE(infrastructure, exit 3).Why
Playwright parses a selector lazily, inside the call that first uses it, so
button[type="submit",xpath=//[,nope=x,div >>, andtext=/(/arrive as ordinary errors.translatePwErrorandclassifyActionErrorpassed those to theirENGINE_FAILUREfallback, so a typo in test code read as an engine fault and an agent treated it as retryable infrastructure. The taxonomy already has the right code for it, and issue #2040 lists the forms a page's own tests can produce.How it works
isSelectorParseErrorinpackages/web/src/support.tsmatches two groups of messages, taken from Playwright 1.65.1: Playwright's ownwhile parsing selectorandwhile parsing css selectorandMalformed selector:(the unknown-engine message already contains the first), and, only when Playwright'slocator.<call>:prefix is there, the browser'sis not a valid XPath expressionand JavaScript'sInvalid regular expressionforxpath=//[andtext=/(/. The prefix keeps an unrelated XPath or regex failure outside a locator call an engine fault, and a test pins that.translatePwError(packages/web/src/support.ts:371) returnsnew TestError('INVALID_LOCATOR', ...)with the raw error as itscauseahead of theENGINE_FAILUREfallback.Surface.guardwraps every operation with this translator by default, so locate, navigation, artifact calls, and theexpecttier all reach it.staleOrchecks the selector beforeSTALE_PATTERN, so alocateon a selector whose text happens to contain "not found" is still a test-code mistake and notNODE_STALE.classifyActionErrorinpackages/web/src/actions.ts:506decides the selector right afterisClassified, before every message-shaped branch, so an action whose selector text contains "not found" or "not editable" is not read as stale or unactionable. Thecauseit attaches is the same sensitive-aware variable the other branches use, so a secret fill still drops the raw Playwright error.ENGINE_ERROR_CODESstays closed: aTestErrorcrosses the engine protocol as a type-e2eerror (packages/core/src/engine/protocol/protocol.ts), so a remote engine keepsINVALID_LOCATORand itstestcategory without adding a code to the engine set.docs/reference/errors.mdxextends theINVALID_LOCATORrow with the selector forms, and the mapping table comment insupport.tsgains the row.Issue
Fixes #2040
Verified
Ran it locally: yes
pnpm --filter @e2e-dev/web exec vitest run tests/unit/errors.test.ts tests/unit/actions.test.ts, first withpackages/web/src/support.tsandactions.tsrestored tomainand the new tests in place, then with the branch. On main the two new tests fail withENGINE_FAILURE; here all 71 pass.page.locator(sel).count()on a blank page.translatePwError(new Error('... while parsing selector ...'), 'locate')returnsENGINE_FAILURE, categoryinfrastructureINVALID_LOCATOR, categorytest, cause keptclassifyActionErroron the same message returnsENGINE_FAILUREINVALID_LOCATOR, categorytest, cause keptstaleOron a parse error containing "not found" returnsNODE_STALE, retryableINVALID_LOCATOR, not retriedpnpm --filter @e2e-dev/web run typecheckandoxlinton the four changed files: clean.>> e2e-read=...selector thatlocateappends. Only the code, the category, and the cause change.Checklist
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).docs/reference/errors.mdx. The skill'sdebuggingreference groupsINVALID_LOCATORwithINVALID_ARGUMENTas a step-argument failure, which stays true..d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures.e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.