[webview_flutter_wkwebview] NSError.toString (#4441)

Fixes https://github.com/flutter/flutter/issues/128596
This commit is contained in:
Ian Hickson
2023-07-11 16:50:50 -07:00
committed by GitHub
parent 6fbc9f9018
commit 1999cdcbae
4 changed files with 49 additions and 2 deletions

View File

@ -1,3 +1,7 @@
## 3.6.3
* Introduces `NSError.toString` for better diagnostics.
## 3.6.2
* Fixes unawaited_futures violations.

View File

@ -215,7 +215,7 @@ class NSError {
/// The error code.
///
/// Note that errors are domain-specific.
/// Error codes are [domain]-specific.
final int code;
/// A string containing the error domain.
@ -223,6 +223,14 @@ class NSError {
/// A string containing the localized description of the error.
final String localizedDescription;
@override
String toString() {
if (localizedDescription.isEmpty) {
return 'Error $domain:$code';
}
return '$localizedDescription ($domain:$code)';
}
}
/// A representation of an HTTP cookie.

View File

@ -2,7 +2,7 @@ name: webview_flutter_wkwebview
description: A Flutter plugin that provides a WebView widget based on Apple's WKWebView control.
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
version: 3.6.2
version: 3.6.3
environment:
sdk: ">=2.18.0 <4.0.0"

View File

@ -246,4 +246,39 @@ void main() {
});
});
});
test('NSError', () {
expect(
const NSError(
code: 0,
domain: 'domain',
localizedDescription: 'desc',
).toString(),
'desc (domain:0)',
);
expect(
const NSError(
code: 0,
domain: 'domain',
localizedDescription: '',
).toString(),
'Error domain:0',
);
expect(
const NSError(
code: 255,
domain: 'bar',
localizedDescription: 'baz',
).toString(),
'baz (bar:255)',
);
expect(
const NSError(
code: 255,
domain: 'bar',
localizedDescription: '',
).toString(),
'Error bar:255',
);
});
}