Skip to content

Commit

Permalink
Feature/pid1102 error reporting system (#328)
Browse files Browse the repository at this point in the history
* Stacktrace stream manager

* stacktrace step as stream and complete stacktrace as string

* error trace

* stacktrace/error reporting, added more events

* changed name to StacktraceManager and added more stacktrace

* stacktrace/error reporting, added more events

* cleaned params passed to stacktrace from the usecases

* hive db used to persist the stacktrace (preparation for next feature)

* test fixed with injection of stack trace manager class

* removed deprecated logger level trace v and wtf

* resolve flutter analyzer issues

* formatting
  • Loading branch information
plusema86 authored Aug 14, 2023
1 parent 544f928 commit 8aba45d
Show file tree
Hide file tree
Showing 103 changed files with 2,058 additions and 1,038 deletions.
12 changes: 6 additions & 6 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,15 @@
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = JHD5NWPZ36;
DEVELOPMENT_TEAM = 6K7H9274Q6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.iden3.polygonid-flutter-sdk.example";
PRODUCT_BUNDLE_IDENTIFIER = "com.polygonid.polygonid-flutter-sdk.example";
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_STYLE = "non-global";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -603,15 +603,15 @@
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = JHD5NWPZ36;
DEVELOPMENT_TEAM = 6K7H9274Q6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.iden3.polygonid-flutter-sdk.example";
PRODUCT_BUNDLE_IDENTIFIER = "com.polygonid.polygonid-flutter-sdk.example";
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_STYLE = "non-global";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -629,15 +629,15 @@
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = JHD5NWPZ36;
DEVELOPMENT_TEAM = 6K7H9274Q6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.iden3.polygonid-flutter-sdk.example";
PRODUCT_BUNDLE_IDENTIFIER = "com.polygonid.polygonid-flutter-sdk.example";
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_STYLE = "non-global";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
</array>
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan QR codes for authentication, claim offers and proof requests</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs photo library access to upload qr code images</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -49,9 +53,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs photo library access to upload qr code images</string>
</dict>
</plist>
14 changes: 0 additions & 14 deletions example/lib/src/common/app_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,10 @@ class AppLogger implements PolygonIdSdkLogger {
}
}

@override
void v(message, [error, StackTrace? stackTrace]) {
if (kDebugMode) {
_logger.v(message, error: error, stackTrace: stackTrace);
}
}

@override
void w(message, [error, StackTrace? stackTrace]) {
if (kDebugMode) {
_logger.w(message, error: error, stackTrace: stackTrace);
}
}

@override
void wtf(message, [error, StackTrace? stackTrace]) {
if (kDebugMode) {
_logger.wtf(message, error: error, stackTrace: stackTrace);
}
}
}
10 changes: 0 additions & 10 deletions lib/common/domain/domain_logger.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
abstract class PolygonIdSdkLogger {
void v(dynamic message, [dynamic error, StackTrace? stackTrace]);

void d(dynamic message, [dynamic error, StackTrace? stackTrace]);

void i(dynamic message, [dynamic error, StackTrace? stackTrace]);

void w(dynamic message, [dynamic error, StackTrace? stackTrace]);

void e(dynamic message, [dynamic error, StackTrace? stackTrace]);

void wtf(dynamic message, [dynamic error, StackTrace? stackTrace]);
}

// Avoid crashing if logger is not defined
Expand All @@ -23,14 +19,8 @@ class NoLogger extends PolygonIdSdkLogger {
@override
void i(message, [error, StackTrace? stackTrace]) {}

@override
void v(message, [error, StackTrace? stackTrace]) {}

@override
void w(message, [error, StackTrace? stackTrace]) {}

@override
void wtf(message, [error, StackTrace? stackTrace]) {}
}

class Domain {
Expand Down
9 changes: 7 additions & 2 deletions lib/common/domain/use_cases/get_env_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import 'package:polygonid_flutter_sdk/common/domain/domain_logger.dart';
import 'package:polygonid_flutter_sdk/common/domain/entities/env_entity.dart';
import 'package:polygonid_flutter_sdk/common/domain/repositories/config_repository.dart';
import 'package:polygonid_flutter_sdk/common/domain/use_case.dart';
import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart';

class GetEnvUseCase extends FutureUseCase<void, EnvEntity> {
final ConfigRepository _configRepository;
final StacktraceManager _stacktraceManager;

GetEnvUseCase(this._configRepository);
GetEnvUseCase(
this._configRepository,
this._stacktraceManager,
);

@override
Future<EnvEntity> execute({dynamic param}) {
Expand All @@ -16,7 +21,7 @@ class GetEnvUseCase extends FutureUseCase<void, EnvEntity> {
return env;
}).catchError((error) {
logger().e("[GetEnvUseCase] Error: $error");

_stacktraceManager.addTrace("[GetEnvUseCase] Error: $error");
throw error;
});
}
Expand Down
69 changes: 69 additions & 0 deletions lib/common/infrastructure/stacktrace_stream_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'dart:async';

import 'package:hive/hive.dart';
import 'package:injectable/injectable.dart';

@lazySingleton
class StacktraceManager {
bool isEnabled = false;
var box = Hive.box('stacktrace');
String _errorTrace = '';
StreamController<String> _stacktraceStreamController =
StreamController<String>.broadcast();

StreamController<String> _errorStreamController =
StreamController<String>.broadcast();

Stream<String> get stacktraceStream => _stacktraceStreamController.stream;

Stream<String> get errorStream => _errorStreamController.stream;

/// we reset the stream
/// so we can use it again
void reset() {
_stacktraceStreamController.close();
_errorStreamController.close();
// we reset the stream
_stacktraceStreamController = StreamController<String>.broadcast();
_errorStreamController = StreamController<String>.broadcast();
}

/// we clear the stacktrace
void clear() {
box.clear();
_errorTrace = '';
_stacktraceStreamController.add('');
_errorStreamController.add(_errorTrace);
}

/// we close the stream
void dispose() {
_stacktraceStreamController.close();
_errorStreamController.close();
}

/// we add a new trace to the stacktrace stream
void addTrace(String stepDescription) {
if (!isEnabled) return;
//write string in an external txt file

String _stacktrace = box.get('stacktrace') ?? '';
_stacktrace += stepDescription + '\n***\n***';
box.put('stacktrace', _stacktrace);
_stacktraceStreamController.add(stepDescription);
}

void addError(String error) {
_errorTrace += '\n***' + error + '\n***';
_errorStreamController.add(error);
}

/// get the stacktrace
String get stacktrace {
String _stacktrace = box.get('stacktrace') ?? '';
return _stacktrace;
}

/// get the error trace
String get errorTrace => _errorTrace;
}
11 changes: 10 additions & 1 deletion lib/credential/data/data_sources/remote_claim_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@ import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart';
import 'package:polygonid_flutter_sdk/common/data/exceptions/network_exceptions.dart';
import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart';

class RemoteClaimDataSource {
final Client client;
final StacktraceManager _stacktraceManager;

RemoteClaimDataSource(this.client);
RemoteClaimDataSource(
this.client,
this._stacktraceManager,
);

Future<Map<String, dynamic>> getClaimRevocationStatus(
String revStatusUrl) async {
var revStatusUri = Uri.parse(revStatusUrl);
_stacktraceManager.addTrace(
"[RemoteClaimDataSource] Getting revocation status from $revStatusUri");
var revStatusResponse = await client.get(revStatusUri, headers: {
HttpHeaders.acceptHeader: '*/*',
HttpHeaders.contentTypeHeader: 'application/json',
});
_stacktraceManager.addTrace(
"[RemoteClaimDataSource] Revocation status response: ${revStatusResponse.statusCode} ${revStatusResponse.body}");
if (revStatusResponse.statusCode == 200) {
String revStatus = (revStatusResponse.body);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:polygonid_flutter_sdk/common/domain/domain_logger.dart';
import 'package:polygonid_flutter_sdk/common/domain/use_case.dart';
import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart';
import 'package:polygonid_flutter_sdk/credential/domain/entities/claim_entity.dart';
import 'package:polygonid_flutter_sdk/credential/domain/repositories/credential_repository.dart';
import 'package:polygonid_flutter_sdk/identity/domain/repositories/identity_repository.dart';
Expand All @@ -20,9 +21,14 @@ class GenerateNonRevProofUseCase
final IdentityRepository _identityRepository;
final CredentialRepository _credentialRepository;
final FetchIdentityStateUseCase _fetchIdentityStateUseCase;
final StacktraceManager _stacktraceManager;

GenerateNonRevProofUseCase(this._identityRepository,
this._credentialRepository, this._fetchIdentityStateUseCase);
GenerateNonRevProofUseCase(
this._identityRepository,
this._credentialRepository,
this._fetchIdentityStateUseCase,
this._stacktraceManager,
);

@override
Future<Map<String, dynamic>> execute(
Expand All @@ -34,6 +40,8 @@ class GenerateNonRevProofUseCase
if (param.nonRevProof != null &&
param.nonRevProof!.isNotEmpty &&
identityState == param.nonRevProof!["issuer"]["state"]) {
_stacktraceManager
.addTrace("[GenerateNonRevProofUseCase] Non rev proof");
return param.nonRevProof!;
} else {
return Future.wait<dynamic>([
Expand All @@ -47,11 +55,15 @@ class GenerateNonRevProofUseCase
baseUrl: values[1],
cachedNonRevProof: param.nonRevProof))
.then((nonRevProof) {
_stacktraceManager
.addTrace("[GenerateNonRevProofUseCase] Non rev proof");
logger()
.i("[GenerateNonRevProofUseCase] Non rev proof: $nonRevProof");

return nonRevProof;
}).catchError((error) {
_stacktraceManager
.addTrace("[GenerateNonRevProofUseCase] Error: $error");
logger().e("[GenerateNonRevProofUseCase] Error: $error");
throw error;
});
Expand Down
11 changes: 10 additions & 1 deletion lib/credential/domain/use_cases/get_auth_claim_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart';
import 'package:polygonid_flutter_sdk/credential/domain/repositories/credential_repository.dart';

import '../../../common/domain/domain_logger.dart';
import '../../../common/domain/use_case.dart';

class GetAuthClaimUseCase extends FutureUseCase<List<String>, List<String>> {
final CredentialRepository _credentialRepository;
final StacktraceManager _stacktraceManager;

GetAuthClaimUseCase(this._credentialRepository);
GetAuthClaimUseCase(
this._credentialRepository,
this._stacktraceManager,
);

@override
Future<List<String>> execute({required List<String> param}) async {
return _credentialRepository
.getAuthClaim(publicKey: param)
.then((authClaim) {
logger().i("[GetAuthClaimUseCase] auth claim: $authClaim");
_stacktraceManager
.addTrace("[GetAuthClaimUseCase] auth claim: $authClaim");
return authClaim;
}).catchError((error) {
logger().e("[GetAuthClaimUseCase] Error: $error");
_stacktraceManager.addTrace("[GetAuthClaimUseCase] Error: $error");
_stacktraceManager.addError("[GetAuthClaimUseCase] Error: $error");
throw error;
});
}
Expand Down
Loading

0 comments on commit 8aba45d

Please sign in to comment.