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

Use trackable package #5

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.22.2"
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ build/
.classpath
.settings
.last_build_id
*.iml
*.iml

# FVM Version Cache
.fvm/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.2.0
- Use `trackable` package
- UnexpectedError is now implementing GeneralTrackableError.
- **Breaking**: Remove TrackingIdService. Use trackable package instead.
- `trackable` package is re-exported with safe_bloc

## 1.1.0
- `errorMapper` parameter added for mapping individual exceptions to bloc/cubit states
- typdefs for callbacks added
Expand Down
2 changes: 2 additions & 0 deletions lib/safe_bloc.dart
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export 'package:trackable/trackable.dart';

export 'src/src.dart';
10 changes: 8 additions & 2 deletions lib/src/safe_bloc_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'dart:io';
import 'package:bloc_presentation/bloc_presentation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:meta/meta.dart';
import 'package:safe_bloc/src/tracking_id_service.dart';
import 'package:safe_bloc/src/unexpected_error.dart';
import 'package:trackable/trackable.dart';

export 'package:bloc/bloc.dart' show Emitter;

Expand Down Expand Up @@ -81,7 +81,13 @@ mixin SafeBlocBaseMixin<STATE, EFFECT> on BlocBase<STATE> {
return await onIgnoreError?.call(e, stacktrace);
}

final error = UnexpectedError(error: e, stackTrace: stacktrace, devMessage: devErrorMessage, isAction: isAction);
final error = UnexpectedError(
error: e,
stackTrace: stacktrace,
devMessage: devErrorMessage,
isAction: isAction,
trackingId: trackingId,
);

final resultingErrorState = errorMapper?.call(e);

Expand Down
3 changes: 2 additions & 1 deletion lib/src/src.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export 'package:trackable/trackable.dart';

export 'base_effect.dart';
export 'bloc_presentation_test.dart';
export 'extensions.dart';
Expand All @@ -6,6 +8,5 @@ export 'safe_bloc_base.dart';
export 'safe_bloc_with_presentation.dart';
export 'safe_cubit.dart';
export 'safe_cubit_with_presentation.dart';
export 'tracking_id_service.dart';
export 'unexpected_error.dart';
export 'unexpected_error_handler.dart';
20 changes: 0 additions & 20 deletions lib/src/tracking_id_service.dart

This file was deleted.

18 changes: 8 additions & 10 deletions lib/src/unexpected_error.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/// Object that stores information about exceptions thrown in Blocs and Cubits.
class UnexpectedError {
// Thrown exception
// Exception or Error has unknown type
// ignore: avoid-dynamic
final dynamic error;
import 'package:trackable/trackable.dart';

/// Object that stores information about exceptions thrown in Blocs and Cubits.
class UnexpectedError extends GeneralTrackableError {
// Exception stacktrace
final StackTrace stackTrace;

Expand All @@ -14,15 +11,16 @@ class UnexpectedError {
// specifies if exception was thrown during the initial data loading (`false`) or during the user action (`true`)
final bool isAction;

const UnexpectedError({
required this.error,
UnexpectedError({
required super.error,
required this.stackTrace,
required super.trackingId,
this.devMessage,
this.isAction = false,
});
}) : super(errorId: ErrorIdService.get());

@override
String toString() => 'UnexpectedError: error. ${devMessage ?? ''}';
String toString() => 'UnexpectedError: error. ${devMessage ?? ''}. ErrorId: $errorId';
}

/// API that is implemented by Bloc/Cubit's error states and effects.
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: safe_bloc
description: An extension to bloc state management library that manages unexpected exceptions.
version: 1.1.0
version: 1.2.0
repository: https://github.com/netglade/safe_bloc
issue_tracker: https://github.com/netglade/safe_bloc/issues
screenshots:
Expand All @@ -20,6 +20,7 @@ dependencies:
flutter_bloc: ^8.1.3
meta: ^1.8.0
test: ^1.24.3
trackable: ^1.0.0
uuid: ^4.1.0

dev_dependencies:
Expand Down
Loading