Skip to content

Commit

Permalink
Change to ArgumentError
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Mar 7, 2024
1 parent 8bc9c3a commit 542ed12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkgs/web_socket/lib/src/browser_web_socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class BrowserWebSocket implements WebSocket {
static Future<BrowserWebSocket> connect(Uri url,
{Iterable<String>? protocols}) async {
if (!url.isScheme('ws') && !url.isScheme('wss')) {
throw WebSocketException("Unsupported URL scheme '${url.scheme}'");
throw ArgumentError.value(
url, 'url', 'only ws: and wss: schemes are supported');
}

final webSocket = web.WebSocket(url.toString(),
Expand Down
5 changes: 5 additions & 0 deletions pkgs/web_socket/lib/src/io_web_socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class IOWebSocket implements WebSocket {
/// [RFC-6455 1.9](https://datatracker.ietf.org/doc/html/rfc6455#section-1.9).
static Future<IOWebSocket> connect(Uri url,
{Iterable<String>? protocols}) async {
if (!url.isScheme('ws') && !url.isScheme('wss')) {
throw ArgumentError.value(
url, 'url', 'only ws: and wss: schemes are supported');
}

final io.WebSocket webSocket;
try {
webSocket =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void testConnectUri(
group('connect uri', () {
test('no protocol', () async {
await expectLater(() => channelFactory(Uri.https('www.example.com', '/')),
throwsA(isA<WebSocketException>()));
throwsA(isA<ArgumentError>()));
});
});
}

0 comments on commit 542ed12

Please sign in to comment.