From 1999cdcbae1c2807aa742c407a47295cc70704e4 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Tue, 11 Jul 2023 16:50:50 -0700 Subject: [PATCH] [webview_flutter_wkwebview] NSError.toString (#4441) Fixes https://github.com/flutter/flutter/issues/128596 --- .../webview_flutter_wkwebview/CHANGELOG.md | 4 +++ .../lib/src/foundation/foundation.dart | 10 +++++- .../webview_flutter_wkwebview/pubspec.yaml | 2 +- .../test/src/foundation/foundation_test.dart | 35 +++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md index 59f6f3d8ed7b..e24e3e0f0057 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.6.3 + +* Introduces `NSError.toString` for better diagnostics. + ## 3.6.2 * Fixes unawaited_futures violations. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart index 818f018d0e32..e8dde5e03dd7 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart @@ -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. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml index 166ab4a0d0e6..9c313c01ef36 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml @@ -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" diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart index a6e042791f06..3dbaea08ede2 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart @@ -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', + ); + }); }