Skip to content

Commit 1ae6d88

Browse files
committed
chore: raise errors instead of asserting on driver replies
Also fix the generator header and the roll skill, which still described the params dicts.
1 parent c96908f commit 1ae6d88

5 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎.claude/skills/playwright-roll/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Failure modes and fixes:
261261
| Symptom | Cause | Fix |
262262
|---|---|---|
263263
| mypy: `"XImpl" has no attribute "y"` in `_generated.py` | The docs have a new member `X.y`; `_impl/` does not. | PORT it. |
264-
| mypy: `Unexpected keyword argument "z" for "y" of "XImpl"` | New parameter or option on an existing method. | Add the parameter in `_impl/` under its Python (snake_case) name, as `Optional[X]` with no default, and put it in the params dict. mypy then reports each caller that must pass it. If Python must not have it, fix the docs: `* langs:` on the option. |
264+
| mypy: `Unexpected keyword argument "z" for "y" of "XImpl"` | New parameter or option on an existing method. | Add the parameter in `_impl/` under its Python (snake_case) name, as `Optional[X]` with no default, and pass it in the channel call. mypy then reports each caller that must pass it. If Python must not have it, fix the docs: `* langs:` on the option. |
265265
| mypy: `Missing named argument "z" for "y" of "XChannel"` | The protocol added a parameter to a command. | Pass the value in the channel call. If the implementation method needs a new parameter for it, add it as above. |
266266
| mypy: incompatible argument type in `_generated.py` | The docs type changed, or `_impl/` declares a narrower type. | Match the type in `_impl/`, or fix the docs with a Python-only declaration (`* langs: python`). |
267267
| generator: `No Python name for the struct at X.y.z` | A new inline `[Object]` with no name in the docs. | Name it in the docs: `` "Name" <[Object]> ``. |

‎playwright/_impl/_fetch.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ async def _inner_fetch(
421421
if max_retries is not None and max_retries < 0:
422422
raise Error("'max_retries' must be greater than or equal to '0'")
423423
url = url or (request.url if request else url)
424-
assert url is not None
424+
if url is None:
425+
raise Error("url: expected a URL string or a Request")
425426
method = method or (request.method if request else "GET")
426427
# Cannot call allHeaders() here as the request may be paused inside route handler.
427428
headers_obj = headers or (request.headers if request else None)

‎playwright/_impl/_har_router.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ async def create(
5353
if result["error"]:
5454
raise Error(result["error"])
5555
har_id = result["harId"]
56-
assert har_id
56+
if har_id is None:
57+
raise Error("harOpen returned no HAR id")
5758
return HarRouter(
5859
local_utils=local_utils,
5960
har_id=har_id,

‎playwright/_impl/_tracing.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ async def _do_stop_chunk(
113113

114114
if is_local:
115115
result = await self._channel.tracingStopChunk(mode="entries")
116-
assert result["entries"] is not None
116+
entries = result["entries"]
117+
if entries is None:
118+
raise Error("tracingStopChunk returned no entries")
117119
await self._connection.local_utils.zip(
118120
zip_file=str(file_path),
119-
entries=result["entries"],
121+
entries=entries,
120122
stacks_id=self._stacks_id,
121123
mode="write",
122124
include_sources=self._include_sources,
@@ -246,10 +248,12 @@ async def _export_har(self, har_id: str) -> None:
246248
if not is_zip:
247249
# Server wrote HAR and resources to the user's chosen paths.
248250
return
249-
assert result["entries"] is not None
251+
entries = result["entries"]
252+
if entries is None:
253+
raise Error("harExport returned no entries")
250254
await self._connection.local_utils.zip(
251255
zip_file=recorder["path"],
252-
entries=result["entries"],
256+
entries=entries,
253257
stacks_id=None,
254258
mode="write",
255259
include_sources=False,
@@ -258,7 +262,8 @@ async def _export_har(self, har_id: str) -> None:
258262
return
259263

260264
result = await self._channel.harExport(harId=har_id, mode="archive")
261-
assert result["artifact"]
265+
if result["artifact"] is None:
266+
raise Error("harExport returned no artifact")
262267
artifact = cast(Artifact, from_channel(result["artifact"]))
263268
if is_zip:
264269
await artifact.save_as(recorder["path"])

‎scripts/codegen/generate_protocol.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
# Generates from the protocol spec (packages/protocol/spec/*.yml in
1616
# microsoft/playwright):
1717
# - playwright/_impl/_protocol.py: the tables that _protocol_check.py uses;
18-
# - playwright/_impl/_protocol_types.py: a TypedDict for each message.
18+
# - playwright/_impl/_protocol_types.py: the TypedDicts of the messages;
19+
# - playwright/_impl/_protocol_channels.py: a typed channel class per interface.
1920
#
2021
# Usage:
21-
# PW_SRC_DIR=<microsoft/playwright checkout> python scripts/codegen/generate_protocol.py --out <file> --types-out <file>
22+
# PW_SRC_DIR=<microsoft/playwright checkout> python scripts/codegen/generate_protocol.py \
23+
# --out <file> --types-out <file> --channels-out <file>
2224
#
2325
# The spec is loaded the same way as utils/protocol_spec.js does it. The output
2426
# is not formatted; run black on it.

0 commit comments

Comments
 (0)