-
Notifications
You must be signed in to change notification settings - Fork 21
Add error checks for accessing Request members #184
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
Conversation
PR HealthChangelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. |
final ref = _value['ref']; | ||
if (ref == null) { | ||
throw ArgumentError('Missing ref field in $CompleteRequest.'); | ||
} | ||
return ref as Reference; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final ref = _value['ref']; | |
if (ref == null) { | |
throw ArgumentError('Missing ref field in $CompleteRequest.'); | |
} | |
return ref as Reference; | |
final ref = _value['ref'] as Reference?; | |
if (ref == null) { | |
throw ArgumentError('Missing ref field in $CompleteRequest.'); | |
} | |
return ref; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pkgs/dart_mcp/CHANGELOG.md
Outdated
@@ -6,6 +6,8 @@ | |||
- Add `clientInfo` field to `MCPServer`, assigned during initialization. | |||
- Move the `done` future from the `ServerConnection` into `MCPBase` so it is | |||
available to the `MPCServer` class as well. | |||
- Added error checking to required fields of all `Request` subclasses so that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh actually this needs to move up into the next version 0.2.3-wip
and the pubspec probably needs to be bumped as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the pubspec/changelog get updated to 0.2.3-wip
Revisions updated by `dart tools/rev_sdk_deps.dart`. ai (https://github.com/dart-lang/ai/compare/706d224..d0b89cf): d0b89cf 2025-06-25 Greg Spencer Add enum support to `Schema` (dart-lang/ai#190) f219861 2025-06-26 Brett Morgan Update `simple_server.dart` (dart-lang/ai#187) 8e3365f 2025-06-24 Greg Spencer Add error checks for accessing Request members (dart-lang/ai#184) protobuf (https://github.com/dart-lang/protobuf/compare/0bfff0c..bce362d): bce362d 2025-06-24 Devon Carew prep to publish 22.4.0 (google/protobuf.dart#1023) 269e004 2025-06-24 Devon Carew improve the readability of generated gRPC client files (google/protobuf.dart#1021) 48ba649 2025-06-24 Devon Carew update the header for generated files (google/protobuf.dart#1022) webdev (https://github.com/dart-lang/webdev/compare/6dc3dde..7f376d2): 7f376d24 2025-06-25 Derek Xu Set package versions to WIP versions (dart-lang/webdev#2637) Change-Id: Ib720f5127f3fddeb82b62cf13f24c3ddb4038e33 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437260 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Auto-Submit: Devon Carew <devoncarew@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Description
This adds error checking and throws
ArgumentError
forRequest
subclasses which have required fields. This is because inshared.dart
, inregisterRequestHandler
, it casts the argument's value to a Map<String, Object?>, but it doesn't do any argument checking because creating those request objects don't go through the constructors, they are just cast:So I added error checking to all of the accessors for required members of
Request
objects, so that when they are accessed they will throw.I ran across this when a client tried to send a malformed initialization request that didn't include capabilities, and the stack trace it sent was less than helpful. This will at least send clearer errors.
Tests