Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of overly broad exception class complicates error handling #4964

Open
auto-d opened this issue Jan 9, 2025 · 2 comments
Open

Use of overly broad exception class complicates error handling #4964

auto-d opened this issue Jan 9, 2025 · 2 comments

Comments

@auto-d
Copy link

auto-d commented Jan 9, 2025

What I did

Sent a message to an agent before the runtime had actually been created. Caught an Exception object from this line as neither my agent or the runtime had been properly set up.

What I was expecting

A more specific Exception object that I could target to handle this case. I currently need to check for this specific error string to avoid catching every Exception that might by raised by the runtime.

@jackgerrits
Copy link
Member

Can you please provide a code example of what you are describing?

@auto-d
Copy link
Author

auto-d commented Jan 16, 2025

Wow this a terrible write-up. I'm sorry, I tried to create the issue from the offending source line and thought a link would be included here, making the exception in question obvious.

Steps to reproduce

  1. Copy the modifier/checker example in the quickstart
  2. Comment one of the agent registration calls like this:

# Create an local embedded runtime.
runtime = SingleThreadedAgentRuntime()

# Register the modifier and checker agents by providing
# their agent types, the factory functions for creating instance and subscriptions.
await Modifier.register(
    runtime,
    "modifier",
    # Modify the value by subtracting 1
    lambda: Modifier(modify_val=lambda x: x - 1),
)

# await Checker.register(
#     runtime,
#     "checker",
#     # Run until the value is less than or equal to 1
#     lambda: Checker(run_until=lambda x: x <= 1),
# )

# Start the runtime and send a direct message to the checker.
runtime.start()
await runtime.send_message(Message(10), AgentId("checker", "default"))
await runtime.stop_when_idle()            
  1. Receive a vanilla Exception with description "Recipient not found"

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

No branches or pull requests

2 participants