Skip to content

Commit 1999cdc

Browse files
authored
[webview_flutter_wkwebview] NSError.toString (#4441)
Fixes flutter/flutter#128596
1 parent 6fbc9f9 commit 1999cdc

4 files changed

Lines changed: 49 additions & 2 deletions

File tree

packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.6.3
2+
3+
* Introduces `NSError.toString` for better diagnostics.
4+
15
## 3.6.2
26

37
* Fixes unawaited_futures violations.

packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,22 @@ class NSError {
215215

216216
/// The error code.
217217
///
218-
/// Note that errors are domain-specific.
218+
/// Error codes are [domain]-specific.
219219
final int code;
220220

221221
/// A string containing the error domain.
222222
final String domain;
223223

224224
/// A string containing the localized description of the error.
225225
final String localizedDescription;
226+
227+
@override
228+
String toString() {
229+
if (localizedDescription.isEmpty) {
230+
return 'Error $domain:$code';
231+
}
232+
return '$localizedDescription ($domain:$code)';
233+
}
226234
}
227235

228236
/// A representation of an HTTP cookie.

packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: webview_flutter_wkwebview
22
description: A Flutter plugin that provides a WebView widget based on Apple's WKWebView control.
33
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
5-
version: 3.6.2
5+
version: 3.6.3
66

77
environment:
88
sdk: ">=2.18.0 <4.0.0"

packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,39 @@ void main() {
246246
});
247247
});
248248
});
249+
250+
test('NSError', () {
251+
expect(
252+
const NSError(
253+
code: 0,
254+
domain: 'domain',
255+
localizedDescription: 'desc',
256+
).toString(),
257+
'desc (domain:0)',
258+
);
259+
expect(
260+
const NSError(
261+
code: 0,
262+
domain: 'domain',
263+
localizedDescription: '',
264+
).toString(),
265+
'Error domain:0',
266+
);
267+
expect(
268+
const NSError(
269+
code: 255,
270+
domain: 'bar',
271+
localizedDescription: 'baz',
272+
).toString(),
273+
'baz (bar:255)',
274+
);
275+
expect(
276+
const NSError(
277+
code: 255,
278+
domain: 'bar',
279+
localizedDescription: '',
280+
).toString(),
281+
'Error bar:255',
282+
);
283+
});
249284
}

0 commit comments

Comments
 (0)