From 2babf27db5e2f4c339525e7808ff83d0524a0e23 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 7 Jul 2023 21:38:04 +1000 Subject: [PATCH] Sentry fix (#395) * Extra sentry diagnostics * Fix unit test * Unit test updates * More unit test updates --- lib/api_form.dart | 2 +- lib/inventree/sentry.dart | 12 +++++++++++- lib/main.dart | 2 ++ lib/user_profile.dart | 4 +++- test/barcode_test.dart | 2 +- test/user_profile_test.dart | 2 +- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/api_form.dart b/lib/api_form.dart index c64ec575..47640ad7 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -586,8 +586,8 @@ class APIFormField { }); } + // Render a "related field" based on the "model" type Widget _renderRelatedField(dynamic item, bool selected, bool extended) { - // Render a "related field" based on the "model" type // Convert to JSON var data = Map.from((item ?? {}) as Map); diff --git a/lib/inventree/sentry.dart b/lib/inventree/sentry.dart index d8becd8c..1d82ff01 100644 --- a/lib/inventree/sentry.dart +++ b/lib/inventree/sentry.dart @@ -1,6 +1,7 @@ import "dart:io"; import "package:device_info_plus/device_info_plus.dart"; +import "package:one_context/one_context.dart"; import "package:package_info_plus/package_info_plus.dart"; import "package:sentry_flutter/sentry_flutter.dart"; @@ -148,7 +149,7 @@ Future sentryReportMessage(String message, {Map? context}) /* * Report an error message to sentry.io */ -Future sentryReportError(String source, dynamic error, dynamic stackTrace, {Map context = const {}}) async { +Future sentryReportError(String source, dynamic error, StackTrace? stackTrace, {Map context = const {}}) async { print("----- Sentry Intercepted error: $error -----"); print(stackTrace); @@ -192,6 +193,15 @@ Future sentryReportError(String source, dynamic error, dynamic stackTrace, // Ensure we pass the 'source' of the error context["source"] = source; + if (OneContext.hasContext) { + final ctx = OneContext().context; + + if (ctx != null) { + context["widget"] = ctx.widget.toString(); + context["widgetType"] = ctx.widget.runtimeType.toString(); + } + } + Sentry.configureScope((scope) { scope.setExtra("server", server_info); scope.setExtra("app", app_info); diff --git a/lib/main.dart b/lib/main.dart index 08b0a305..aa2adb60 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -38,6 +38,8 @@ Future main() async { options.dsn = SENTRY_DSN_KEY; options.release = release; options.environment = isInDebugMode() ? "debug" : "release"; + options.diagnosticLevel = SentryLevel.debug; + options.attachStacktrace = true; }); // Pass any flutter errors off to the Sentry reporting context! diff --git a/lib/user_profile.dart b/lib/user_profile.dart index 53d7c0dc..e1b54467 100644 --- a/lib/user_profile.dart +++ b/lib/user_profile.dart @@ -98,7 +98,7 @@ class UserProfileDBManager { if (exists) { debug("addProfile() : UserProfile '${profile.name}' already exists"); - return false; + return true; } else { debug("Adding new profile: '${profile.name}'"); } @@ -137,6 +137,8 @@ class UserProfileDBManager { * Remove a user profile from the database */ Future deleteProfile(UserProfile profile) async { + debug("deleteProfile: ${profile.name}"); + await store.record(profile.key).delete(await _db); } diff --git a/test/barcode_test.dart b/test/barcode_test.dart index e896f440..e28715b3 100644 --- a/test/barcode_test.dart +++ b/test/barcode_test.dart @@ -26,7 +26,7 @@ void main() { final prf = await UserProfileDBManager().getProfileByName("Test Profile"); if (prf != null) { - UserProfileDBManager().deleteProfile(prf); + await UserProfileDBManager().deleteProfile(prf); } bool result = await UserProfileDBManager().addProfile( diff --git a/test/user_profile_test.dart b/test/user_profile_test.dart index 144a146b..1da201fa 100644 --- a/test/user_profile_test.dart +++ b/test/user_profile_test.dart @@ -79,7 +79,7 @@ void main() { ) ); - expect(result, equals(false)); + expect(result, equals(true)); // Check that the number of protocols available is still the same var profiles = await UserProfileDBManager().getAllProfiles();