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: logging and gracefully handle bad cache stores (#4810)

Myles Scolnicka15f4006a6eb
diff --git a/marimo/_save/stores/__init__.py b/marimo/_save/stores/__init__.py
index 965d808787..1953343186 100644
--- a/marimo/_save/stores/__init__.py
+++ b/marimo/_save/stores/__init__.py
@@ -1,11 +1,14 @@
# Copyright 2025 Marimo. All rights reserved.
from typing import Literal
+from marimo import _loggers
from marimo._save.stores.file import FileStore
from marimo._save.stores.redis import RedisStore
from marimo._save.stores.rest import RestStore
from marimo._save.stores.store import Store, StoreType
+LOGGER = _loggers.marimo_logger()
+
StoreKey = Literal["file", "redis", "rest"]
CACHE_STORES: dict[StoreKey, StoreType] = {
@@ -27,8 +30,14 @@ def get_store() -> Store:
.get("cache", {})
)
store_type = cache_config.get("store", DEFAULT_STORE_KEY)
- assert store_type in CACHE_STORES, f"Invalid store type: {store_type}"
- return CACHE_STORES[store_type](**cache_config.get("args", {}))
+ if store_type not in CACHE_STORES:
+ LOGGER.error(f"Invalid store type: {store_type}")
+ store_type = DEFAULT_STORE_KEY
+ try:
+ return CACHE_STORES[store_type](**cache_config.get("args", {}))
+ except Exception as e:
+ LOGGER.error(f"Error creating store: {e}")
+ return DEFAULT_STORE()
__all__ = [