From 113abd9a8c0ff56475e638eaaf67060ff32ae517 Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Tue, 2 Jul 2024 17:54:22 +0800 Subject: [PATCH 1/4] feat: Add throwException handler --- lib/src/iris_method_channel.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/src/iris_method_channel.dart b/lib/src/iris_method_channel.dart index 00ded2f..dd8984a 100644 --- a/lib/src/iris_method_channel.dart +++ b/lib/src/iris_method_channel.dart @@ -9,6 +9,19 @@ import 'package:iris_method_channel/src/platform/iris_method_channel_internal.da // ignore_for_file: public_member_api_docs +@pragma('vm:prefer-inline') +ThrowExceptionHandler throwException = _defaultThrowExceptionBuilder; +@pragma('vm:prefer-inline') +void _defaultThrowExceptionBuilder({required int code, String? message}) { + throw Exception(); +} + +typedef ExceptionBuilder = Exception Function( + {required int code, String? message}); + +typedef ThrowExceptionHandler = void Function( + {required int code, String? message}); + class IrisMethodChannel { IrisMethodChannel(this._nativeBindingsProvider) { _irisMethodChannelInternal = From 27529f236ce26d7231feaca9d939c9ade63b546f Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Fri, 9 Aug 2024 15:02:55 +0800 Subject: [PATCH 2/4] feat: Add throwExceptionHandler --- lib/src/iris_method_channel.dart | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/src/iris_method_channel.dart b/lib/src/iris_method_channel.dart index dd8984a..446a702 100644 --- a/lib/src/iris_method_channel.dart +++ b/lib/src/iris_method_channel.dart @@ -10,15 +10,12 @@ import 'package:iris_method_channel/src/platform/iris_method_channel_internal.da // ignore_for_file: public_member_api_docs @pragma('vm:prefer-inline') -ThrowExceptionHandler throwException = _defaultThrowExceptionBuilder; +ThrowExceptionHandler throwExceptionHandler = _defaultThrowExceptionHandler; @pragma('vm:prefer-inline') -void _defaultThrowExceptionBuilder({required int code, String? message}) { +void _defaultThrowExceptionHandler({required int code, String? message}) { throw Exception(); } -typedef ExceptionBuilder = Exception Function( - {required int code, String? message}); - typedef ThrowExceptionHandler = void Function( {required int code, String? message}); From 62e10a1f4eff25b4c31becd923876c68452d281d Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Fri, 9 Aug 2024 15:13:09 +0800 Subject: [PATCH 3/4] feat: Add throwExceptionHandler --- test/iris_method_channel_test.dart | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/iris_method_channel_test.dart b/test/iris_method_channel_test.dart index eaedb2c..3bd6edf 100644 --- a/test/iris_method_channel_test.dart +++ b/test/iris_method_channel_test.dart @@ -867,4 +867,32 @@ void main() { await irisMethodChannel.dispose(); }, ); + + test( + 'throwExceptionHandler throw Exception by default', + () async { + final currentThrowExceptionHandler = throwExceptionHandler; + + expect(() => throwExceptionHandler(code: 1, message: 'message'), + throwsA(isA())); + + throwExceptionHandler = currentThrowExceptionHandler; + }, + ); + + test( + 'Can override throwExceptionHandler', + () async { + final currentThrowExceptionHandler = throwExceptionHandler; + + throwExceptionHandler = ({required int code, String? message}) { + throw StateError('message'); + }; + + expect(() => throwExceptionHandler(code: 1, message: 'message'), + throwsA(isA())); + + throwExceptionHandler = currentThrowExceptionHandler; + }, + ); } From 515b9168795940b10c385486c426fdb5eba7d6c0 Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Tue, 13 Aug 2024 11:09:00 +0800 Subject: [PATCH 4/4] feat: Add throwExceptionHandler --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 098d226..edc6b36 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -242,7 +242,7 @@ jobs: integration_test_ios: name: ios integration test if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci:skip') }} - runs-on: macos-13 + runs-on: macos-14 timeout-minutes: 60 steps: - uses: actions/checkout@v1 @@ -264,7 +264,7 @@ jobs: integration_test_ios_use_frameworks: name: ios integration test with use_frameworks if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci:skip') }} - runs-on: macos-13 + runs-on: macos-14 timeout-minutes: 60 steps: - uses: actions/checkout@v1