Skip to content

Commit 5242438

Browse files
authored
Merge branch 'main' into cam/465/revert-serialization-from-442
2 parents 1ca51ff + 17c3f9f commit 5242438

4 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Remove the `orjson` dependency [[#478](https://github.com/plotly/Kaleido/pull/478)]
99

1010
### Fixed
11+
- Add the browser path to message in `ChromeNotFoundError` when it was set with `path=` or `BROWSER_PATH` and points to nothing [[#476](https://github.com/plotly/Kaleido/pull/476)], with thanks to @Blizzeq for the contribution!
1112
- Restore serialization of figure specs through the `plotly` JSON encoder [[#478](https://github.com/plotly/Kaleido/pull/478)]
1213

1314
## v1.4.0

‎src/py/kaleido/kaleido.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import os
67
import warnings
78
from collections import deque
89
from collections.abc import AsyncIterable, Iterable
@@ -184,12 +185,19 @@ def __init__( # noqa: PLR0913
184185
try:
185186
super().__init__(**kwargs)
186187
except ChromeNotFoundError:
187-
raise ChromeNotFoundError(
188+
msg = (
188189
"Kaleido v1 and later requires Chrome to be installed. "
189190
"To install Chrome, use the CLI command `kaleido_get_chrome`, "
190191
"or from Python, use either `await kaleido.get_chrome()` "
191-
"or `kaleido.get_chrome_sync()`.",
192-
) from None # overwriting the error entirely. (diagnostics)
192+
"or `kaleido.get_chrome_sync()`."
193+
)
194+
# a path the user set explicitly is the likelier cause
195+
if browser_path := kwargs.get("path"):
196+
msg = f"No browser found at path={str(browser_path)!r}. {msg}"
197+
elif browser_path := os.environ.get("BROWSER_PATH"):
198+
msg = f"No browser found at BROWSER_PATH={browser_path!r}. {msg}"
199+
# overwriting the error entirely. (diagnostics)
200+
raise ChromeNotFoundError(msg) from None
193201

194202
# save this for open() because it requires close()
195203
self._saved_page_arg = page

‎src/py/tests/test_kaleido.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from unittest.mock import AsyncMock, patch
77

88
import pytest
9+
from choreographer.browsers import chromium
910
from hypothesis import HealthCheck, given, settings
1011
from hypothesis import strategies as st
1112

1213
from kaleido import Kaleido
14+
from kaleido.errors import ChromeNotFoundError
1315

1416
if TYPE_CHECKING:
1517
from collections.abc import AsyncGenerator, Generator
@@ -338,6 +340,22 @@ async def test_kaleido_instantiate_and_close():
338340
await k.close()
339341

340342

343+
async def test_kaleido_reports_bad_path():
344+
"""Test that a browser path passed by the user is named in the error."""
345+
with pytest.raises(ChromeNotFoundError, match="path='/nonexistent/chrome'"):
346+
Kaleido(path="/nonexistent/chrome")
347+
348+
349+
async def test_kaleido_reports_bad_browser_path_env(monkeypatch):
350+
"""Test that a BROWSER_PATH set by the user is named in the error."""
351+
monkeypatch.setenv("BROWSER_PATH", "/nonexistent/chrome")
352+
# a downloaded chrome takes precedence over BROWSER_PATH, so hide it
353+
monkeypatch.setattr(chromium, "get_chrome_download_path", lambda **_: None)
354+
monkeypatch.setattr(chromium, "get_old_chrome_download_path", lambda: None)
355+
with pytest.raises(ChromeNotFoundError, match="BROWSER_PATH='/nonexistent/chrome'"):
356+
Kaleido()
357+
358+
341359
async def test_all_methods_context(simple_figure_with_bytes, tmp_path):
342360
"""Test write, write_from_object, and calc with context."""
343361
fig = simple_figure_with_bytes["fig"]

‎src/py/uv.lock‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)