diff --git a/lib/api.dart b/lib/api.dart index e69f7564..9994b655 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -574,7 +574,15 @@ class InvenTreeAPI { // Ignore TypeError } else { // Unknown error - report it! - sentryReportError(error, stackTrace); + sentryReportError( + "api.checkPermission", + error, stackTrace, + context: { + "role": role, + "permission": permission, + "error": error.toString(), + } + ); } // Unable to determine permission - assume true? @@ -668,7 +676,10 @@ class InvenTreeAPI { } catch (error, stackTrace) { print("Server error at ${url}: ${error.toString()}"); showServerError(L10().serverError, error.toString()); - sentryReportError(error, stackTrace); + sentryReportError( + "api.downloadFile : client.openUrl", + error, stackTrace, + ); return; } @@ -692,10 +703,14 @@ class InvenTreeAPI { showServerError(L10().connectionRefused, error.toString()); } on TimeoutException { showTimeoutError(); - } catch (error) { + } catch (error, stackTrace) { print("Error downloading image:"); print(error.toString()); showServerError(L10().downloadError, error.toString()); + sentryReportError( + "api.downloadFile : client.closeRequest", + error, stackTrace, + ); } } @@ -779,7 +794,10 @@ class InvenTreeAPI { response.error = "TimeoutException"; } catch (error, stackTrace) { showServerError(L10().serverError, error.toString()); - sentryReportError(error, stackTrace); + sentryReportError( + "api.uploadFile", + error, stackTrace + ); response.error = "UnknownError"; response.errorDetail = error.toString(); } @@ -930,7 +948,14 @@ class InvenTreeAPI { } catch (error, stackTrace) { print("Server error at ${url}: ${error.toString()}"); showServerError(L10().serverError, error.toString()); - sentryReportError(error, stackTrace); + sentryReportError( + "api.apiRequest : openUrl", + error, stackTrace, + context: { + "url": url, + "method": method, + } + ); return null; } } @@ -996,13 +1021,16 @@ class InvenTreeAPI { showServerError(L10().connectionRefused, error.toString()); response.error = "SocketException"; response.errorDetail = error.toString(); - + } on CertificateException catch (error) { + print("CertificateException at ${request.uri.toString()}:"); + print(error.toString()); + showServerError(L10().serverCertificateError, error.toString()); } on TimeoutException { showTimeoutError(); response.error = "TimeoutException"; } catch (error, stackTrace) { showServerError(L10().serverError, error.toString()); - sentryReportError(error, stackTrace); + sentryReportError("api.completeRequest", error, stackTrace); response.error = "UnknownError"; response.errorDetail = error.toString(); } diff --git a/lib/api_form.dart b/lib/api_form.dart index ff827598..07221a1e 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -788,7 +788,14 @@ Map extractFieldDefinition(Map data, String lo print(error.toString()); // Report the error - sentryReportError(error, stackTrace); + sentryReportError( + "apiForm.extractFieldDefinition : path traversal", + error, stackTrace, + context: { + "path": path.toString(), + "el": el, + } + ); return {}; } } @@ -808,7 +815,13 @@ Map extractFieldDefinition(Map data, String lo print(error.toString()); // Report the error - sentryReportError(error, stacktrace); + sentryReportError( + "apiForm.extractFieldDefinition : as map", + error, stacktrace, + context: { + "el": el.toString(), + } + ); return {}; } diff --git a/lib/inventree/sentry.dart b/lib/inventree/sentry.dart index 79a8ea56..429a50af 100644 --- a/lib/inventree/sentry.dart +++ b/lib/inventree/sentry.dart @@ -142,7 +142,7 @@ Future sentryReportMessage(String message, {Map? context}) } -Future sentryReportError(dynamic error, dynamic stackTrace) async { +Future sentryReportError(String source, dynamic error, dynamic stackTrace, {Map context = const {}}) async { print("----- Sentry Intercepted error: $error -----"); print(stackTrace); @@ -167,10 +167,14 @@ Future sentryReportError(dynamic error, dynamic stackTrace) async { final app_info = await getAppInfo(); final device_info = await getDeviceInfo(); + // Ensure we pass the 'source' of the error + context["source"] = source; + Sentry.configureScope((scope) { scope.setExtra("server", server_info); scope.setExtra("app", app_info); scope.setExtra("device", device_info); + scope.setExtra("context", context); }); Sentry.captureException(error, stackTrace: stackTrace).catchError((error) { diff --git a/lib/main.dart b/lib/main.dart index 9d97ccc4..ea0703f1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -39,7 +39,15 @@ Future main() async { FlutterError.onError = (FlutterErrorDetails details) async { // Ensure that the error gets reported to sentry! - await sentryReportError(details.exception, details.stack); + await sentryReportError( + "FlutterError.onError", + details.exception, details.stack, + context: { + "context": details.context.toString(), + "summary": details.summary.toString(), + "library": details.library ?? "null", + } + ); }; runApp( @@ -47,7 +55,7 @@ Future main() async { ); }, (Object error, StackTrace stackTrace) async { - sentryReportError(error, stackTrace); + sentryReportError("main.runZonedGuarded", error, stackTrace); }); } diff --git a/lib/widget/paginator.dart b/lib/widget/paginator.dart index f1bfbc85..aa62647d 100644 --- a/lib/widget/paginator.dart +++ b/lib/widget/paginator.dart @@ -86,7 +86,10 @@ class PaginatedSearchState extends State { } catch (error, stackTrace) { _pagingController.error = error; - sentryReportError(error, stackTrace); + sentryReportError( + "paginator.fetchPage", + error, stackTrace, + ); } }