Skip to content

fix: replace print() with logger and strengthen error handling#215

Open
crazywriter1 wants to merge 2 commits intoOpenGradient:mainfrom
crazywriter1:fix/error-handling-observability
Open

fix: replace print() with logger and strengthen error handling#215
crazywriter1 wants to merge 2 commits intoOpenGradient:mainfrom
crazywriter1:fix/error-handling-observability

Conversation

@crazywriter1
Copy link
Copy Markdown

Summary

  • alpha.py — Replace two print() calls with logger.warning() so gas estimation failures and scheduler registration errors are captured by the caller's logging infrastructure instead of going to stdout
  • alpha.py — Change raise Exception(...) to raise RuntimeError(...) in new_workflow to match the exception type used consistently everywhere else in the codebase; updated docstring to reflect that gas estimation failure uses a fallback instead of raising
  • alpha.py — Fixed _register_with_scheduler docstring: previously claimed Raises: Exception but the method never raises — errors are caught, logged, and swallowed intentionally since the workflow contract is already deployed
  • llm.py — Strengthen the choices[] guard in _chat_request: added isinstance(choices, list) and isinstance(choices[0], dict) checks — the previous if not choices guard passes silently for [None] or non-list types, which then crashes with an unhelpful AttributeError
  • llm.py / types.py — Log malformed SSE JSON chunks with logger.warning() instead of silently continue-ing, making it visible when the server sends broken data during streaming

Files Changed

  • src/opengradient/client/alpha.py
  • src/opengradient/client/llm.py
  • src/opengradient/types.py
  • tests/client_test.py

Test Plan

  • Full test suite passes: uv run pytest tests/ -v121 passed
  • TestChoicesGuard — verifies choices=[] and choices=[None] both raise RuntimeError
  • TestSSEJsonLogging — verifies malformed SSE JSON emits logger.warning, valid chunks do not
  • TestAlphaErrorHandling — verifies deployment failure raises RuntimeError, gas estimation failure and scheduler failure both call logger.warning

- Replace print() calls in alpha.py with logger.warning()
- Standardize exception type: bare Exception -> RuntimeError in new_workflow
- Guard choices parsing in llm.py _chat_request with list and dict checks
- Log malformed SSE JSON in llm.py and types.py streaming parsers

Signed-off-by: crazywriter1 <crazywriter1@users.noreply.github.com>
@adambalogh
Copy link
Copy Markdown
Collaborator

Hey, would you mind merging from main? Thanks!

…servability

# Conflicts:
#	src/opengradient/client/alpha.py
@crazywriter1
Copy link
Copy Markdown
Author

Done. Merged from main and force pushed. Thanks for the review. @adambalogh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants