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

Better toString on custom exceptions #140

Merged
merged 4 commits into from
Dec 12, 2023
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
140 changes: 64 additions & 76 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "medea-jason"
version = "0.4.0"
version = "0.4.1-dev"
edition = "2021"
rust-version = "1.65"
description = "Client library for Medea media server."
Expand Down
12 changes: 12 additions & 0 deletions flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ All user visible changes to this project will be documented in this file. This p



## [0.4.1] · 2023-??-??
[0.4.1]: /../../tree/medea-jason-0.4.1/flutter

### Added

- More information in `toString()` on custom exceptions ([#140]).

[#140]: /../../pull/140




## [0.4.0] · 2023-07-11
[0.4.0]: /../../tree/medea-jason-0.4.0/flutter

Expand Down
2 changes: 1 addition & 1 deletion flutter/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.4.0"
version: "0.4.1-dev"
meta:
dependency: transitive
description:
Expand Down
44 changes: 31 additions & 13 deletions flutter/lib/src/interface/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,49 @@ enum MediaStateTransitionExceptionKind {
}

/// Exception thrown when cannot get info of available media devices.
abstract class EnumerateDevicesException {
abstract class EnumerateDevicesException implements Exception {
/// Returns error that caused this [EnumerateDevicesException].
dynamic cause();

/// Returns stacktrace of this [EnumerateDevicesException].
String trace();

@override
String toString() {
return 'EnumerateDevicesException: ${cause()}\n${trace()}';
}
}

/// Exception thrown when cannot switch output audio device ID.
abstract class InvalidOutputAudioDeviceIdException {
abstract class InvalidOutputAudioDeviceIdException implements Exception {
/// Returns stacktrace of this [InvalidOutputAudioDeviceIdException].
String trace();

@override
String toString() {
return 'InvalidOutputAudioDeviceIdException:\n${trace()}';
}
}

/// Exception thrown when cannot interact with microphone volume.
abstract class MicVolumeException {
abstract class MicVolumeException implements Exception {
/// Returns error that caused this [MicVolumeException].
dynamic cause();

/// Returns stacktrace of this [MicVolumeException].
String trace();

@override
String toString() {
return 'MicVolumeException: ${cause()}\n${trace()}';
}
}

/// Jason's internal exception.
///
/// This is either a programmatic error or some unexpected platform component
/// failure that cannot be handled in any way.
abstract class InternalException {
abstract class InternalException implements Exception {
/// Returns error message describing the problem.
String message();

Expand All @@ -96,12 +111,12 @@ abstract class InternalException {

@override
String toString() {
return message();
return 'InternalException: ${message()}, ${cause()}\n${trace()}';
}
}

/// Exception thrown when accessing media devices.
abstract class LocalMediaInitException {
abstract class LocalMediaInitException implements Exception {
/// Returns concrete error kind of this [LocalMediaInitException].
LocalMediaInitExceptionKind kind();

Expand All @@ -116,12 +131,13 @@ abstract class LocalMediaInitException {

@override
String toString() {
return message();
return 'LocalMediaInitException: ${kind().name}, ${message()}, ${cause()}'
'\n${trace()}';
}
}

/// Errors occurring in `RoomHandle.set_local_media_settings` method.
abstract class MediaSettingsUpdateException {
abstract class MediaSettingsUpdateException implements Exception {
/// Returns error message describing the problem.
String message();

Expand All @@ -135,13 +151,13 @@ abstract class MediaSettingsUpdateException {

@override
String toString() {
return message();
return 'MediaSettingsUpdateException: ${message()}, ${cause()}';
}
}

/// Exception thrown when the requested media state transition could not be
/// performed.
abstract class MediaStateTransitionException {
abstract class MediaStateTransitionException implements Exception {
/// Returns error message describing the problem.
String message();

Expand All @@ -153,13 +169,14 @@ abstract class MediaStateTransitionException {

@override
String toString() {
return message();
return 'MediaStateTransitionException: ${kind().name}, ${message()}'
'\n${trace()}';
}
}

/// Exceptions thrown from an RPC client that implements messaging with media
/// server.
abstract class RpcClientException {
abstract class RpcClientException implements Exception {
/// Returns concrete error kind of this [RpcClientException].
RpcClientExceptionKind kind();

Expand All @@ -174,6 +191,7 @@ abstract class RpcClientException {

@override
String toString() {
return message();
return 'RpcClientException: ${kind().name}, ${message()}, ${cause()}'
'\n${trace()}';
}
}
19 changes: 8 additions & 11 deletions flutter/lib/src/native/ffi/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ class NativePanicException implements Exception {
}

/// Exception thrown when local media acquisition fails.
class NativeLocalMediaInitException
implements LocalMediaInitException, Exception {
class NativeLocalMediaInitException extends LocalMediaInitException {
/// Concrete error kind of this [NativeLocalMediaInitException].
late final LocalMediaInitExceptionKind _kind;

Expand Down Expand Up @@ -168,8 +167,7 @@ class NativeLocalMediaInitException
/// Exception thrown when cannot get info about connected [MediaDevices][1].
///
/// [1]: https://w3.org/TR/mediacapture-streams#mediadevices
class NativeEnumerateDevicesException
implements EnumerateDevicesException, Exception {
class NativeEnumerateDevicesException extends EnumerateDevicesException {
/// Dart [Exception] or [Error] that caused this [NativeEnumerateDevicesException].
late final Object _cause;

Expand All @@ -192,7 +190,7 @@ class NativeEnumerateDevicesException

/// Exception thrown when cannot switch audio output device ID.
class NativeInvalidOutputAudioDeviceIdException
implements InvalidOutputAudioDeviceIdException {
extends InvalidOutputAudioDeviceIdException {
/// Native stacktrace.
late final String _nativeStackTrace;

Expand All @@ -206,7 +204,7 @@ class NativeInvalidOutputAudioDeviceIdException
}

/// Exception thrown when cannot interact with microphone volume.
class NativeMicVolumeException implements MicVolumeException {
class NativeMicVolumeException extends MicVolumeException {
/// Dart [Exception] or [Error] that caused this [NativeMicVolumeException].
late final Object _cause;

Expand All @@ -229,7 +227,7 @@ class NativeMicVolumeException implements MicVolumeException {

/// Exceptions thrown from `Jason`'s `RpcClient` which implements messaging with
/// media server.
class NativeRpcClientException implements RpcClientException, Exception {
class NativeRpcClientException extends RpcClientException {
/// Concrete error kind of this [NativeRpcClientException].
late final RpcClientExceptionKind _kind;

Expand Down Expand Up @@ -270,7 +268,7 @@ class NativeRpcClientException implements RpcClientException, Exception {
/// Exception thrown when the requested media state transition could not be
/// performed.
class NativeMediaStateTransitionException
implements MediaStateTransitionException, Exception {
extends MediaStateTransitionException {
/// Error message describing the problem.
late final String _message;

Expand Down Expand Up @@ -304,7 +302,7 @@ class NativeMediaStateTransitionException
///
/// This is either a programmatic error or some unexpected platform component
/// failure that cannot be handled in any way.
class NativeInternalException implements InternalException, Exception {
class NativeInternalException extends InternalException {
/// Error message describing the problem.
late final String _message;

Expand Down Expand Up @@ -335,8 +333,7 @@ class NativeInternalException implements InternalException, Exception {

/// Exception that might happen when updating local media settings via
/// `RoomHandle.setLocalMediaSettings`.
class NativeMediaSettingsUpdateException
implements MediaSettingsUpdateException, Exception {
class NativeMediaSettingsUpdateException extends MediaSettingsUpdateException {
/// Error message describing the problem.
late final String _message;

Expand Down
13 changes: 6 additions & 7 deletions flutter/lib/src/web/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Future<T> fallibleFuture<T>(Future<T> f) async {
}

/// Exception thrown when cannot get info of available media devices.
class WebEnumerateDevicesException implements EnumerateDevicesException {
class WebEnumerateDevicesException extends EnumerateDevicesException {
late dynamic _cause;
late String _trace;

Expand All @@ -99,7 +99,7 @@ class WebEnumerateDevicesException implements EnumerateDevicesException {
///
/// This is either a programmatic error or some unexpected platform component
/// failure that cannot be handled in any way.
class WebInternalException implements InternalException {
class WebInternalException extends InternalException {
late String _message;
late dynamic _cause;
late String _trace;
Expand Down Expand Up @@ -131,7 +131,7 @@ class WebInternalException implements InternalException {
}

/// Exception thrown when accessing media devices.
class WebLocalMediaInitException implements LocalMediaInitException {
class WebLocalMediaInitException extends LocalMediaInitException {
late LocalMediaInitExceptionKind _kind;
late String _message;
late dynamic _cause;
Expand Down Expand Up @@ -171,7 +171,7 @@ class WebLocalMediaInitException implements LocalMediaInitException {
}

/// Errors occurring in `RoomHandle::set_local_media_settings()` method.
class WebMediaSettingsUpdateException implements MediaSettingsUpdateException {
class WebMediaSettingsUpdateException extends MediaSettingsUpdateException {
late String _message;
late dynamic _cause;
late bool _rolledBack;
Expand Down Expand Up @@ -205,8 +205,7 @@ class WebMediaSettingsUpdateException implements MediaSettingsUpdateException {

/// Exception thrown when the requested media state transition could not be
/// performed.
class WebMediaStateTransitionException
implements MediaStateTransitionException {
class WebMediaStateTransitionException extends MediaStateTransitionException {
late String _message;
late String _trace;
late MediaStateTransitionExceptionKind _kind;
Expand Down Expand Up @@ -239,7 +238,7 @@ class WebMediaStateTransitionException

/// Exceptions thrown from an RPC client that implements messaging with a media
/// server.
class WebRpcClientException implements RpcClientException {
class WebRpcClientException extends RpcClientException {
late RpcClientExceptionKind _kind;
late String _message;
late dynamic _cause;
Expand Down
2 changes: 1 addition & 1 deletion flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: medea_jason
description: Cross-platform client library of Medea media server for Flutter.
version: 0.4.0
version: 0.4.1-dev
homepage: https://github.com/instrumentisto/medea-jason/blob/master/flutter

environment:
Expand Down
Loading