Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: handle OSErrors when seraching for pyproject.toml (#6726)

Akshay Agrawal046c64dc73ef
diff --git a/marimo/_config/reader.py b/marimo/_config/reader.py
index c2acc9ca36..1fb6a66e68 100644
--- a/marimo/_config/reader.py
+++ b/marimo/_config/reader.py
@@ -52,10 +52,13 @@ def find_nearest_pyproject_toml(
"""Find the nearest pyproject.toml file."""
path = Path(start_path)
root = path.anchor
- while not path.joinpath("pyproject.toml").exists():
- if str(path) == root:
- return None
- if path.parent == path:
- return None
- path = path.parent
+ try:
+ while not path.joinpath("pyproject.toml").exists():
+ if str(path) == root:
+ return None
+ if path.parent == path:
+ return None
+ path = path.parent
+ except OSError:
+ return None
return path.joinpath("pyproject.toml")
diff --git a/tests/_config/test_reader.py b/tests/_config/test_reader.py
index f88c7bb144..8b8e2af462 100644
--- a/tests/_config/test_reader.py
+++ b/tests/_config/test_reader.py
@@ -111,7 +111,7 @@ def test_read_pyproject_config_no_file(tmp_path: Path):
assert nearest_pyproject_toml is None
-def testfind_nearest_pyproject_toml():
+def test_find_nearest_pyproject_toml():
with tempfile.TemporaryDirectory() as temp_dir:
parent_dir = os.path.join(temp_dir, "parent")
os.makedirs(parent_dir)
@@ -125,12 +125,19 @@ def testfind_nearest_pyproject_toml():
assert result == Path(pyproject_path)
-def testfind_nearest_pyproject_toml_not_found():
+def test_find_nearest_pyproject_toml_not_found():
with tempfile.TemporaryDirectory() as temp_dir:
result = find_nearest_pyproject_toml(temp_dir)
assert result is None
+def test_find_nearest_pyproject_toml_permission_error():
+ with patch("pathlib.Path.exists") as mock_exists:
+ mock_exists.side_effect = PermissionError("Permission denied")
+ result = find_nearest_pyproject_toml("/some/path")
+ assert result is None
+
+
def test_read_toml_invalid_content():
invalid_toml = b"""
[invalid