python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

fix: improve misleading warning for progress callback exceptions

Open lorenzocesconetto opened this issue 8 months ago • 4 comments

Currently if the progress notification callback throws an exception we get a misleading warning message. This PR aims to fix it.

Motivation and Context

How Has This Been Tested?

Ran a few tests locally.

Breaking Changes

No breaking changes.

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation update

Checklist

  • [x] I have read the MCP Documentation
  • [x] My code follows the repository's style guidelines
  • [x] New and existing tests pass locally
  • [x] I have added appropriate error handling
  • [x] I have added or updated documentation as needed

Additional context

lorenzocesconetto avatar May 21 '25 20:05 lorenzocesconetto

Hi @ihrpr thank you for the review. I'll add the tests.

lorenzocesconetto avatar May 23 '25 18:05 lorenzocesconetto

Hi @ihrpr, ready for another pass! I've added the unit test and removed the try-except-else as you've requested.

lorenzocesconetto avatar May 25 '25 00:05 lorenzocesconetto

Why is it misleading? Do you have a MRE that I can check this locally?

Also, if this makes sense, we should except on ValidationError, not on Exception.

Kludex avatar May 26 '25 09:05 Kludex

Thank you for your reviews and comments @Kludex and @ihrpr! Totally agree with you guys and changed to ValidationError in the try-except. I only kept the generic Exception around the callback execution since we don't know what kind of exception might be raised in there.

@Kludex the "misleading" part is that it prints Failed to validate notification... when the user's callback raises an exception. When I saw that for the first time I thought the server notification message was not following the protocol's standard (or the client validation was broken). That message is very misleading. The root cause was a bad implementation of the callback.

lorenzocesconetto avatar May 29 '25 01:05 lorenzocesconetto

@ihrpr can you take another look?

lorenzocesconetto avatar Jun 03 '25 01:06 lorenzocesconetto

Hi @felixweinberger, thanks for getting back to me, I'll update this PR. I am actually interested in contributing more to this repo as long as core contributors are willing to provide quick feedback. Lmk if there's any other issues across the repo that could use an extra pair of hands.

lorenzocesconetto avatar Sep 07 '25 16:09 lorenzocesconetto

Hi @felixweinberger, thanks for getting back to me, I'll update this PR. I am actually interested in contributing more to this repo as long as core contributors are willing to provide quick feedback. Lmk if there's any other issues across the repo that could use an extra pair of hands.

Thank you for the feedback and yes it's something we're currently working on the team to improve coverage for (so we can get back to people more quickly). I'll be sure to get back to you quickly on this PR.

Thank you for the offer of making more contributions! I'm currently trying to get a handle on clusters of issues on the python SDK worth prioritizing, I'll let you know if I find something suitable that needs some help!

felixweinberger avatar Sep 08 '25 17:09 felixweinberger

@felixweinberger pulled the latest changes and resolved the conflicts. But it seems that one of the tests is breaking for python 3.10 but runs successfully for other versions, interesting...

lorenzocesconetto avatar Sep 09 '25 00:09 lorenzocesconetto

@felixweinberger pulled the latest changes and resolved the conflicts. But it seems that one of the tests is breaking for python 3.10 but runs successfully for other versions, interesting...

Thanks! There is occasional flakiness in the tests, I restarted it let's see if it was one of those.

felixweinberger avatar Sep 09 '25 14:09 felixweinberger

@felixweinberger thanks for moving forward with this.

lorenzocesconetto avatar Sep 30 '25 17:09 lorenzocesconetto