Better error message on invalid use lf lastvalue channel

This commit is contained in:
Nuno Campos
2024-01-17 13:51:17 -08:00
parent c12c7583c8
commit aa2eb4606d
2 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ class LastValue(Generic[Value], BaseChannel[Value, Value, Value]):
if len(values) == 0:
return
if len(values) != 1:
raise InvalidUpdateError()
raise InvalidUpdateError("LastValue can only receive one value per step.")
self.value = values[-1]
+7 -1
View File
@@ -46,6 +46,7 @@ from langgraph.channels.base import (
BaseChannel,
ChannelsManager,
EmptyChannelError,
InvalidUpdateError,
create_checkpoint,
)
from langgraph.channels.last_value import LastValue
@@ -684,7 +685,12 @@ def _apply_writes(
# Apply writes to channels
for chan, vals in pending_writes_by_channel.items():
if chan in channels:
channels[chan].update(vals)
try:
channels[chan].update(vals)
except InvalidUpdateError as e:
raise InvalidUpdateError(
f"Invalid update for channel {chan}: {e}"
) from e
checkpoint["channel_versions"][chan] += 1
updated_channels.add(chan)
else: