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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: handle TOML parsing errors in config reader (#3671)
devin-ai-integration[bot]6c1791e6f518
diff --git a/marimo/_utils/config/config.py b/marimo/_utils/config/config.pyindex 9749461f05..54f6c63e77 100644--- a/marimo/_utils/config/config.py+++ b/marimo/_utils/config/config.py@@ -36,7 +36,7 @@ class ConfigReader:with open(self.filepath, "r") as file:data = tomlkit.parse(file.read())return parse_raw(data, cls, allow_unknown_keys=True)- except FileNotFoundError:+ except (FileNotFoundError, tomlkit.exceptions.TOMLKitError):return fallbackdef write_toml(self, data: Any) -> None:diff --git a/tests/_utils/config/__init__.py b/tests/_utils/config/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/tests/_utils/config/test_config_reader.py b/tests/_utils/config/test_config_reader.pynew file mode 100644index 0000000000..bccbd7674b--- /dev/null+++ b/tests/_utils/config/test_config_reader.py@@ -0,0 +1,40 @@+# Copyright 2024 Marimo. All rights reserved.+from __future__ import annotations++import os+from dataclasses import dataclass+from tempfile import NamedTemporaryFile++from marimo._utils.config.config import ConfigReader+++@dataclass+class TestConfig:+ value: str+++def test_read_toml_invalid_syntax() -> None:+ with NamedTemporaryFile(mode="w", suffix=".toml", delete=False) as f:+ # Write invalid TOML content (missing value after comma)+ f.write("key = 'value',")+ f.flush()++ reader = ConfigReader(f.name)+ fallback = TestConfig(value="fallback")+ result = reader.read_toml(TestConfig, fallback=fallback)+ assert result == fallback++ os.unlink(f.name)+++def test_read_toml_valid() -> None:+ with NamedTemporaryFile(mode="w", suffix=".toml", delete=False) as f:+ f.write('value = "test"')+ f.flush()++ reader = ConfigReader(f.name)+ fallback = TestConfig(value="fallback")+ result = reader.read_toml(TestConfig, fallback=fallback)+ assert result == TestConfig(value="test")++ os.unlink(f.name)