Skip to content

Commit

Permalink
fixed: error, stacktrace, data, hint, & message
Browse files Browse the repository at this point in the history
  • Loading branch information
we-prajapati-c001 committed Oct 22, 2024
1 parent 6f50e89 commit 1c1f964
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 105 deletions.
6 changes: 5 additions & 1 deletion lib/vaahextendflutter/env/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class EnvController extends GetxController {
throw Exception('Environment configuration not found for key: $envPath');
}
} catch (error, stackTrace) {
Log.exception(error, stackTrace: stackTrace);
Log.exception(
"Error occured while initializing EnvController",
throwable: error,
stackTrace: stackTrace,
);
exit(0);
}
}
Expand Down
13 changes: 11 additions & 2 deletions lib/vaahextendflutter/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ abstract class Api {
bool showAlert,
String alertType,
) async {
Log.exception(error, stackTrace: error.stackTrace);
Log.exception(
"Handle Timeout Error",
throwable: error,
stackTrace: error.stackTrace,
);
if (showAlert) {
if (alertType == 'dialog') {
if (Alerts.showErrorDialog != null) {
Expand Down Expand Up @@ -416,7 +420,12 @@ abstract class Api {

if (error.response?.data != null) {
try {
Log.exception(catchErr, data: error.response, stackTrace: stackTrace);
Log.exception(
"Handle Response Error",
throwable: catchErr,
hint: error.response,
stackTrace: stackTrace,
);

final Map<String, dynamic> response = error.response?.data as Map<String, dynamic>;
if (response['errors'] != null) {
Expand Down
21 changes: 12 additions & 9 deletions lib/vaahextendflutter/services/dynamic_links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class DynamicLinks {
shortLinkType: ShortDynamicLinkType.unguessable,
);
} catch (error, stackTrace) {
Log.exception(error, stackTrace: stackTrace, hint: "Error creating dynamic link!");
Log.exception("Error creating dynamic link!", throwable: error, stackTrace: stackTrace);
return null;
}
}
Expand All @@ -61,10 +61,13 @@ abstract class DynamicLinks {
decoded: "${linkData.link.host}${linkData.link.path}?payload=$payload",
),
);
Log.success({
"encoded": linkData.link.toString(),
"decoded": "${linkData.link.host}${linkData.link.path}?payload=$payload",
});
Log.success(
"Handle Deeplink",
data: {
"encoded": linkData.link.toString(),
"decoded": "${linkData.link.host}${linkData.link.path}?payload=$payload",
},
);
if (payload != null && payload['path'] != null) {
Get.to(
payload['path'],
Expand All @@ -76,9 +79,9 @@ abstract class DynamicLinks {
}
} catch (error, stackTrace) {
Log.exception(
error,
"Error handling dynamic link! ${linkData.asMap()}",
throwable: error,
stackTrace: stackTrace,
hint: "Error handling dynamic link! ${linkData.asMap()}",
);
}
}
Expand All @@ -88,9 +91,9 @@ abstract class DynamicLinks {
return jsonDecode(link.queryParameters['payload'].toString());
} catch (error, stackTrace) {
Log.exception(
error,
"Error decoding payload! $link",
throwable: error,
stackTrace: stackTrace,
hint: "Error decoding payload! $link",
);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import '../models/log.dart';
import 'logging_service.dart';

abstract class FirebaseLoggingService implements LoggingService {
static logEvent({
required String message,
EventType? type,
static logEvent(
String message, {
Object? data,
EventType? type,
}) =>
throw UnimplementedError();

static logException(
dynamic throwable, {
dynamic stackTrace,
String message, {
Object? throwable,
StackTrace? stackTrace,
dynamic hint,
}) =>
throw UnimplementedError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import '../models/log.dart';
import 'logging_service.dart';

abstract class SentryLoggingService implements LoggingService {
static logEvent({
required String message,
SentryLevel? level,
static logEvent(
String message, {
Object? data,
SentryLevel? level,
}) {
final SentryEvent event = SentryEvent(message: SentryMessage(message), level: level);
Sentry.captureEvent(
Expand All @@ -17,11 +17,19 @@ abstract class SentryLoggingService implements LoggingService {
}

static logException(
dynamic throwable, {
dynamic stackTrace,
String message, {
Object? throwable,
StackTrace? stackTrace,
dynamic hint,
}) {
Sentry.captureException(throwable, stackTrace: stackTrace, hint: hint);
Sentry.captureException(
throwable,
stackTrace: stackTrace,
hint: Hint.withMap({
"message": message,
"hint": hint,
}),
);
}

static logTransaction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ class Console {
final RegExp pattern = RegExp('.{1,800}'); // 800 is the size of each chunk
pattern.allMatches(text).forEach((RegExpMatch match) {
if (logStyle == null || logStyle.isEmpty) {
return debugPrint(
match.group(0),
);
return debugPrint(match.group(0));
}

Colorize chunk = Colorize(match.group(0).toString()).apply(logStyle.first);
return debugPrint(
'$chunk',
);
return debugPrint('$chunk');
});
}

Expand All @@ -32,61 +27,98 @@ class Console {
}
}

static void log(String text, [Object? data]) {
_printLog(text);
static void log(
String message, {
Object? data,
}) {
_printLog(message);

if (data != null) {
_printLog(_parseData(data), {
Styles.WHITE,
});
_printLog(_parseData(data));
}
}

static void info(String text, [Object? data]) {
_printLog(text, {
Styles.BLUE,
});
static void info(
String message, {
Object? data,
}) {
_printLog(
message,
{Styles.BLUE},
);

if (data != null) {
_printLog(_parseData(data), {
Styles.BLUE,
});
_printLog(
_parseData(data),
{Styles.BLUE},
);
}
}

static void success(String text, [Object? data]) {
_printLog(text, {
Styles.GREEN,
});
static void success(
String message, {
Object? data,
}) {
_printLog(
message,
{Styles.GREEN},
);

if (data != null) {
_printLog(_parseData(data), {
Styles.GREEN,
});
_printLog(
_parseData(data),
{Styles.GREEN},
);
}
}

static void warning(String text, [Object? data]) {
_printLog(text, {
Styles.YELLOW,
});
static void warning(
String message, {
Object? data,
}) {
_printLog(
message,
{Styles.YELLOW},
);

if (data != null) {
_printLog(_parseData(data), {
Styles.YELLOW,
});
_printLog(
_parseData(data),
{Styles.YELLOW},
);
}
}

static void danger(String text, [Object? data]) {
_printLog(text, {
Styles.RED,
});
static void danger(
String message, {
Object? throwable,
StackTrace? stackTrace,
dynamic hint,
}) {
_printLog(
message,
{Styles.RED},
);

if (throwable != null) {
_printLog(
_parseData(throwable),
{Styles.RED},
);
}

if (data != null) {
_printLog(_parseData(data), {
Styles.RED,
});
if (stackTrace != null) {
_printLog(
stackTrace.toString(),
{Styles.RED},
);
}

if (hint != null) {
_printLog(
_parseData(hint),
{Styles.RED},
);
}
}

Expand Down
Loading

0 comments on commit 1c1f964

Please sign in to comment.