Skip to content

Commit 984cc43

Browse files
authored
Fix a bug where ConnectionException.toString didn't stringify NSError (#1785)
1 parent 2d9681d commit 984cc43

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

pkgs/cupertino_http/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.1-wip
2+
3+
* Make `ConnectionException.toString` more helpful.
4+
15
## 2.2.0
26

37
* Cancel requests when the response stream is cancelled.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:cupertino_http/cupertino_http.dart';
6+
import 'package:objective_c/objective_c.dart';
7+
import 'package:test/test.dart';
8+
9+
void main() {
10+
group('ConnectionException', () {
11+
test('toString', () {
12+
expect(
13+
ConnectionException(
14+
'failed to connect',
15+
NSError.errorWithDomain_code_userInfo_(
16+
'NSURLErrorDomain'.toNSString(), -999, null))
17+
.toString(),
18+
'CupertinoErrorWebSocketException: failed to connect '
19+
'[The operation couldn’t be completed. '
20+
'(NSURLErrorDomain error -999.)]');
21+
});
22+
});
23+
}

pkgs/cupertino_http/lib/src/cupertino_web_socket.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class ConnectionException extends WebSocketException {
1818
ConnectionException(super.message, this.error);
1919

2020
@override
21-
String toString() => 'CupertinoErrorWebSocketException: $message $error';
21+
String toString() => 'CupertinoErrorWebSocketException: $message '
22+
'[${error.localizedDescription.toDartString()}]';
2223
}
2324

2425
/// A [WebSocket] implemented using the

pkgs/cupertino_http/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: cupertino_http
2-
version: 2.2.0
2+
version: 2.2.1-wip
33
description: >-
44
A macOS/iOS Flutter plugin that provides access to the Foundation URL
55
Loading System.

0 commit comments

Comments
 (0)