From 399fa19d75496037356804659469aff0dcac5c83 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 1 Jul 2025 10:38:25 -0700 Subject: [PATCH] Fix a bug where ConnectionException.toString didn't stringify NSError --- pkgs/cupertino_http/CHANGELOG.md | 4 ++++ .../integration_test/web_socket_test.dart | 23 +++++++++++++++++++ .../lib/src/cupertino_web_socket.dart | 3 ++- pkgs/cupertino_http/pubspec.yaml | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 pkgs/cupertino_http/example/integration_test/web_socket_test.dart diff --git a/pkgs/cupertino_http/CHANGELOG.md b/pkgs/cupertino_http/CHANGELOG.md index b5b1c56c8d..023f168386 100644 --- a/pkgs/cupertino_http/CHANGELOG.md +++ b/pkgs/cupertino_http/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.1-wip + +* Make `ConnectionException.toString` more helpful. + ## 2.2.0 * Cancel requests when the response stream is cancelled. diff --git a/pkgs/cupertino_http/example/integration_test/web_socket_test.dart b/pkgs/cupertino_http/example/integration_test/web_socket_test.dart new file mode 100644 index 0000000000..9c4d0c5528 --- /dev/null +++ b/pkgs/cupertino_http/example/integration_test/web_socket_test.dart @@ -0,0 +1,23 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:cupertino_http/cupertino_http.dart'; +import 'package:objective_c/objective_c.dart'; +import 'package:test/test.dart'; + +void main() { + group('ConnectionException', () { + test('toString', () { + expect( + ConnectionException( + 'failed to connect', + NSError.errorWithDomain_code_userInfo_( + 'NSURLErrorDomain'.toNSString(), -999, null)) + .toString(), + 'CupertinoErrorWebSocketException: failed to connect ' + '[The operation couldn’t be completed. ' + '(NSURLErrorDomain error -999.)]'); + }); + }); +} diff --git a/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart b/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart index c7868e0efe..8dc8ebf2a6 100644 --- a/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart +++ b/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart @@ -18,7 +18,8 @@ class ConnectionException extends WebSocketException { ConnectionException(super.message, this.error); @override - String toString() => 'CupertinoErrorWebSocketException: $message $error'; + String toString() => 'CupertinoErrorWebSocketException: $message ' + '[${error.localizedDescription.toDartString()}]'; } /// A [WebSocket] implemented using the diff --git a/pkgs/cupertino_http/pubspec.yaml b/pkgs/cupertino_http/pubspec.yaml index f04fd14357..ced1645311 100644 --- a/pkgs/cupertino_http/pubspec.yaml +++ b/pkgs/cupertino_http/pubspec.yaml @@ -1,5 +1,5 @@ name: cupertino_http -version: 2.2.0 +version: 2.2.1-wip description: >- A macOS/iOS Flutter plugin that provides access to the Foundation URL Loading System.