Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add throwExceptionHandler #102

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/src/iris_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import 'package:iris_method_channel/src/platform/iris_method_channel_internal.da

// ignore_for_file: public_member_api_docs

@pragma('vm:prefer-inline')
ThrowExceptionHandler throwExceptionHandler = _defaultThrowExceptionHandler;
@pragma('vm:prefer-inline')
void _defaultThrowExceptionHandler({required int code, String? message}) {
throw Exception();
}

typedef ThrowExceptionHandler = void Function(
{required int code, String? message});

class IrisMethodChannel {
IrisMethodChannel(this._nativeBindingsProvider) {
_irisMethodChannelInternal =
Expand Down
28 changes: 28 additions & 0 deletions test/iris_method_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exception>()));

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<StateError>()));

throwExceptionHandler = currentThrowExceptionHandler;
},
);
}
Loading