Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions oocana/oocana/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,23 @@ async def oomol_token(self) -> str:
"""
return os.getenv("OOMOL_TOKEN", "")

def _wrap_output_with_warning(self, key: str, value: Any) -> tuple[Any, bool]:
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other helper methods in the Context class (such as __wrap_output_value, __is_basic_type, __store_ref, __dataframe, __matplotlib), this method should use double underscores (__wrap_output_with_warning) rather than a single underscore to indicate it's a private method.

Copilot uses AI. Check for mistakes.
"""
Wrap output value with error handling.

Args:
key: The output handle key
value: The value to wrap

Returns:
A tuple of (wrapped_value, success). If success is False, wrapped_value is None.
"""
try:
return self.__wrap_output_value(key, value), True
except (ValueError, IOError) as e:
self.send_warning(f"{e}")
return None, False
Comment on lines +437 to +452
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description mentions that three methods (output, outputs, and finish) had identical try/except patterns that should be refactored. However, the finish() method at lines 514-523 still contains the duplicate try/except pattern and was not updated to use the new _wrap_output_with_warning() helper method. This method should also be refactored for consistency.

Copilot uses AI. Check for mistakes.

def output(self, key: str, value: Any, *, to_node: list[ToNode] | None = None, to_flow: list[ToFlow] | None = None):
"""
output the value to the next block
Expand All @@ -444,57 +461,35 @@ def output(self, key: str, value: Any, *, to_node: list[ToNode] | None = None, t
:param to_flow: list[ToFlow] | None, the target flow(with output handle) to send the output
if both to_node and to_flow are None, the output will be sent to all connected nodes and flows.
"""

try:
wrap_value = self.__wrap_output_value(key, value)
except ValueError as e:
self.send_warning(
f"{e}"
)
return
except IOError as e:
self.send_warning(
f"{e}"
)
wrap_value, success = self._wrap_output_with_warning(key, value)
if not success:
return

target = None
if to_node is not None or to_flow is not None:
target = {
"to_node": to_node,
"to_flow": to_flow,
}
else:
target = None
target = {"to_node": to_node, "to_flow": to_flow}

payload = {
payload: Dict[str, Any] = {
"type": "BlockOutput",
"handle": key,
"output": wrap_value,
}
if target is not None:
payload["options"] = {"target": target}
self.__mainframe.send(self.job_info, payload)

def outputs(self, outputs: Dict[str, Any]):
"""
output the value to the next block

map: Dict[str, Any], the key of the output, should be defined in the block schema output defs, the field name is handle
"""

values = {}
for key, value in outputs.items():
try:
wrap_value = self.__wrap_output_value(key, value)
wrap_value, success = self._wrap_output_with_warning(key, value)
if success:
values[key] = wrap_value
except ValueError as e:
self.send_warning(
f"{e}"
)
except IOError as e:
self.send_warning(
f"{e}"
)

self.__mainframe.send(self.job_info, {
"type": "BlockOutputs",
"outputs": values,
Expand Down
Loading