jax-ml/jax · error · ValueError
key cannot be empty
Error message
key cannot be empty
What it means
LRUCache.get validates that the cache key is non-empty before building the cache file path; an empty (or falsy) key would map to a degenerate filename, so it raises ValueError. Keys are hashed strings naming compilation-cache entries.
Source
Thrown at jax/_src/lru_cache.py:94
self.lock_timeout_secs = lock_timeout_secs
self.lock_path = self.path / ".lockfile"
if _is_local_filesystem(path):
self.lock = filelock.FileLock(self.lock_path)
else:
self.lock = filelock.SoftFileLock(self.lock_path)
def get(self, key: str) -> bytes | None:
"""Retrieves the cached value for the given key.
Args:
key: The key for which the cache value is retrieved.
Returns:
The cached data as bytes if available; ``None`` otherwise.
"""
if not key:
raise ValueError("key cannot be empty")
cache_path = self.path / f"{key}{_CACHE_SUFFIX}"
if self.eviction_enabled:
self.lock.acquire(timeout=self.lock_timeout_secs)
try:
if not cache_path.exists():
logger.debug(f"Cache miss for key: {key!r}")
return None
logger.debug(f"Cache hit for key: {key!r}")
val = cache_path.read_bytes()
if self.eviction_enabled:
timestamp = time.time_ns().to_bytes(8, "little")
atime_path = self.path / f"{key}{_ATIME_SUFFIX}"View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Ensure the key is a non-empty string (typically a hash hex digest) before calling get
- If generating keys yourself, fall back to a stable hash of the empty input
Example fix
# before value = cache.get(key if key else '') # after value = cache.get(key) if key else None
Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(key, str) and key, 'cache key must be a non-empty string'
Type guard
def is_valid_key(k) -> bool:
return isinstance(k, str) and len(k) > 0 Prevention
- Always derive keys from a hash of inputs
- Never pass optional/None keys through to cache APIs
When it happens
Trigger: Calling cache.get('') or cache.get(None) on a jax._src.lru_cache.LRUCache; indirectly if user code computes a cache key from strings that can be empty.
Common situations: Custom wrappers around the compilation cache that derive keys from possibly-empty names/paths; only hit by internal or advanced users of jax._src.lru_cache.
Related errors
- numpy masked arrays are not supported as direct inputs to JA
- Invalid compute type {c_type}. Current supported values are
- numpy masked arrays are not supported as direct inputs to JA
- Mesh axis names cannot be None. Got: {axis_names}
- Mesh requires the ndim of its first argument (`devices`) to
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/6994164ba4588950.
Report an issue: GitHub.