lancedb/lancedb · error · ValueError
Cannot add note to exception
Error message
Cannot add note to exception
What it means
add_note attaches a note to an exception either via the Python 3.11+ add_note method, or by string-concatenating onto args[0] if args[0] is a str. If the base exception's first arg is not a string and add_note is unavailable, it raises ValueError('Cannot add note to exception').
Solutions
- Upgrade to Python 3.11+ where native add_note is always used
- Before calling, ensure the target exception has a string first arg, or re-wrap it: raise type(exc)(str(exc)) from exc
- Wrap the original exception in a RuntimeError with the note instead of mutating it
Example fix
// before
add_note(exc, "embedding setup failed") # ValueError if exc.args[0] not str
// after
if not (hasattr(exc, "add_note") or (exc.args and isinstance(exc.args[0], str))):
exc = RuntimeError(str(exc))
add_note(exc, "embedding setup failed") Defensive patterns
Strategy: try-catch
Validate before calling
def can_annotate(exc) -> bool:
return hasattr(exc, "add_note") or bool(exc.args and isinstance(exc.args[0], str)) Type guard
def annotatable(exc: BaseException) -> bool:
return hasattr(exc, "add_note") or (exc.args and isinstance(exc.args[0], str)) Try / catch
try:
add_note(exc, note)
except ValueError as e:
if "Cannot add note" in str(e):
raise RuntimeError(f"{note}: {exc!r}") from exc
raise Prevention
- Run on Python 3.11+ so native add_note is always available
- Wrap non-string-arg exceptions in RuntimeError before annotating
- Never rely on mutating exceptions produced by third-party code with exotic args
When it happens
Trigger: Calling add_note(exc, note) (directly or via _add_unique_note in the embedding error path, e.g. __resolveVariables/get_embedding_func failures) on an exception whose args[0] is not a str (e.g. KeyError with non-string key, custom exception taking an int) on Python < 3.11.
Common situations: Annotating exceptions raised by libraries that pass non-string payloads (KeyError('missing_col') actually has str args, but KeyError(404) does not); running on Python 3.10 or older where Exception.add_note does not exist.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- a Function environment is pip or conda, not both
- add_columns cannot mix a Function application with SQL…
- add_columns cannot take both transforms and computed columns
- add_columns requires transforms or computed columns
- All datasets in a HuggingFace DatasetDict must have the…
AI-assisted analysis of lancedb/lancedb@c7b051aff7 (2026-09-08).
Data as JSON: /api/errors/cda23e8d42ac5cb2.
Report an issue: GitHub.
Appendix: source
Thrown at python/python/lancedb/util.py:459
return new_func
def validate_table_name(name: str):
"""Verify the table name is valid."""
native_validate_table_name(name)
def add_note(base_exception: BaseException, note: str):
if hasattr(base_exception, "add_note"):
base_exception.add_note(note)
elif isinstance(base_exception.args[0], str):
base_exception.args = (
base_exception.args[0] + "\n" + note,
*base_exception.args[1:],
)
else:
raise ValueError("Cannot add note to exception")
def tbl_to_tensor(tbl: pa.Table):
"""
Convert a PyArrow Table to a PyTorch Tensor.
Each column is converted to a tensor (using zero-copy via DLPack)
and the columns are then stacked into a single tensor.
Fails if torch is not installed.
Fails if any column is more than one chunk.
Fails if a column's data type is not supported by PyTorch.
Parameters
----------
tbl : pa.Table or pa.RecordBatch
The table or record batch to convert to a tensor.
View on GitHub (pinned to c7b051aff7)