mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-11-03 23:05:44 +00:00 
			
		
		
		
	Merge pull request #129 from inventree/better-sentry
Add extra context information to sentry error reports
This commit is contained in:
		@@ -5,11 +5,12 @@
 | 
				
			|||||||
---
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Refactor home screen display
 | 
					- Refactor home screen display
 | 
				
			||||||
- Display unread notifications on home screen
 | 
					- Display notification messages from InvenTree server
 | 
				
			||||||
- Fixes duplicated display of units when showing stock quantity
 | 
					- Fixes duplicated display of units when showing stock quantity
 | 
				
			||||||
- Adds ability to locate / identify stock items or locations (requires server plugin)
 | 
					- Adds ability to locate / identify stock items or locations (requires server plugin)
 | 
				
			||||||
- Improve rendering of home screen when server is not connected
 | 
					- Improve rendering of home screen when server is not connected
 | 
				
			||||||
- Adds ability to load global and user settings from the server
 | 
					- Adds ability to load global and user settings from the server
 | 
				
			||||||
 | 
					- Translation updates
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 0.6.2 - April 2022
 | 
					### 0.6.2 - April 2022
 | 
				
			||||||
---
 | 
					---
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										42
									
								
								lib/api.dart
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								lib/api.dart
									
									
									
									
									
								
							@@ -574,7 +574,15 @@ class InvenTreeAPI {
 | 
				
			|||||||
        // Ignore TypeError
 | 
					        // Ignore TypeError
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        // Unknown error - report it!
 | 
					        // 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?
 | 
					      // Unable to determine permission - assume true?
 | 
				
			||||||
@@ -668,7 +676,10 @@ class InvenTreeAPI {
 | 
				
			|||||||
    } catch (error, stackTrace) {
 | 
					    } catch (error, stackTrace) {
 | 
				
			||||||
      print("Server error at ${url}: ${error.toString()}");
 | 
					      print("Server error at ${url}: ${error.toString()}");
 | 
				
			||||||
      showServerError(L10().serverError, error.toString());
 | 
					      showServerError(L10().serverError, error.toString());
 | 
				
			||||||
      sentryReportError(error, stackTrace);
 | 
					      sentryReportError(
 | 
				
			||||||
 | 
					        "api.downloadFile : client.openUrl",
 | 
				
			||||||
 | 
					        error, stackTrace,
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -692,10 +703,14 @@ class InvenTreeAPI {
 | 
				
			|||||||
      showServerError(L10().connectionRefused, error.toString());
 | 
					      showServerError(L10().connectionRefused, error.toString());
 | 
				
			||||||
    } on TimeoutException {
 | 
					    } on TimeoutException {
 | 
				
			||||||
      showTimeoutError();
 | 
					      showTimeoutError();
 | 
				
			||||||
    } catch (error) {
 | 
					    } catch (error, stackTrace) {
 | 
				
			||||||
      print("Error downloading image:");
 | 
					      print("Error downloading image:");
 | 
				
			||||||
      print(error.toString());
 | 
					      print(error.toString());
 | 
				
			||||||
      showServerError(L10().downloadError, error.toString());
 | 
					      showServerError(L10().downloadError, error.toString());
 | 
				
			||||||
 | 
					      sentryReportError(
 | 
				
			||||||
 | 
					        "api.downloadFile : client.closeRequest",
 | 
				
			||||||
 | 
					        error, stackTrace,
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -779,7 +794,10 @@ class InvenTreeAPI {
 | 
				
			|||||||
      response.error = "TimeoutException";
 | 
					      response.error = "TimeoutException";
 | 
				
			||||||
    } catch (error, stackTrace) {
 | 
					    } catch (error, stackTrace) {
 | 
				
			||||||
      showServerError(L10().serverError, error.toString());
 | 
					      showServerError(L10().serverError, error.toString());
 | 
				
			||||||
      sentryReportError(error, stackTrace);
 | 
					      sentryReportError(
 | 
				
			||||||
 | 
					        "api.uploadFile",
 | 
				
			||||||
 | 
					        error, stackTrace
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
      response.error = "UnknownError";
 | 
					      response.error = "UnknownError";
 | 
				
			||||||
      response.errorDetail = error.toString();
 | 
					      response.errorDetail = error.toString();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -930,7 +948,14 @@ class InvenTreeAPI {
 | 
				
			|||||||
    } catch (error, stackTrace) {
 | 
					    } catch (error, stackTrace) {
 | 
				
			||||||
      print("Server error at ${url}: ${error.toString()}");
 | 
					      print("Server error at ${url}: ${error.toString()}");
 | 
				
			||||||
      showServerError(L10().serverError, error.toString());
 | 
					      showServerError(L10().serverError, error.toString());
 | 
				
			||||||
      sentryReportError(error, stackTrace);
 | 
					      sentryReportError(
 | 
				
			||||||
 | 
					        "api.apiRequest : openUrl",
 | 
				
			||||||
 | 
					        error, stackTrace,
 | 
				
			||||||
 | 
					        context: {
 | 
				
			||||||
 | 
					          "url": url,
 | 
				
			||||||
 | 
					          "method": method,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
      return null;
 | 
					      return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -996,13 +1021,16 @@ class InvenTreeAPI {
 | 
				
			|||||||
      showServerError(L10().connectionRefused, error.toString());
 | 
					      showServerError(L10().connectionRefused, error.toString());
 | 
				
			||||||
      response.error = "SocketException";
 | 
					      response.error = "SocketException";
 | 
				
			||||||
      response.errorDetail = error.toString();
 | 
					      response.errorDetail = error.toString();
 | 
				
			||||||
 | 
					    } on CertificateException catch (error) {
 | 
				
			||||||
 | 
					      print("CertificateException at ${request.uri.toString()}:");
 | 
				
			||||||
 | 
					      print(error.toString());
 | 
				
			||||||
 | 
					      showServerError(L10().serverCertificateError, error.toString());
 | 
				
			||||||
    } on TimeoutException {
 | 
					    } on TimeoutException {
 | 
				
			||||||
      showTimeoutError();
 | 
					      showTimeoutError();
 | 
				
			||||||
      response.error = "TimeoutException";
 | 
					      response.error = "TimeoutException";
 | 
				
			||||||
    } catch (error, stackTrace) {
 | 
					    } catch (error, stackTrace) {
 | 
				
			||||||
      showServerError(L10().serverError, error.toString());
 | 
					      showServerError(L10().serverError, error.toString());
 | 
				
			||||||
      sentryReportError(error, stackTrace);
 | 
					      sentryReportError("api.completeRequest", error, stackTrace);
 | 
				
			||||||
      response.error = "UnknownError";
 | 
					      response.error = "UnknownError";
 | 
				
			||||||
      response.errorDetail = error.toString();
 | 
					      response.errorDetail = error.toString();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -788,7 +788,14 @@ Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lo
 | 
				
			|||||||
      print(error.toString());
 | 
					      print(error.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Report the error
 | 
					      // Report the error
 | 
				
			||||||
      sentryReportError(error, stackTrace);
 | 
					      sentryReportError(
 | 
				
			||||||
 | 
					        "apiForm.extractFieldDefinition : path traversal",
 | 
				
			||||||
 | 
					        error, stackTrace,
 | 
				
			||||||
 | 
					        context: {
 | 
				
			||||||
 | 
					          "path": path.toString(),
 | 
				
			||||||
 | 
					          "el": el,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
      return {};
 | 
					      return {};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -808,7 +815,13 @@ Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lo
 | 
				
			|||||||
      print(error.toString());
 | 
					      print(error.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Report the error
 | 
					      // Report the error
 | 
				
			||||||
      sentryReportError(error, stacktrace);
 | 
					      sentryReportError(
 | 
				
			||||||
 | 
					        "apiForm.extractFieldDefinition : as map",
 | 
				
			||||||
 | 
					        error, stacktrace,
 | 
				
			||||||
 | 
					        context: {
 | 
				
			||||||
 | 
					          "el": el.toString(),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return {};
 | 
					      return {};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -142,7 +142,7 @@ Future<bool> sentryReportMessage(String message, {Map<String, String>? context})
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Future<void> sentryReportError(dynamic error, dynamic stackTrace) async {
 | 
					Future<void> sentryReportError(String source, dynamic error, dynamic stackTrace, {Map<String, String> context = const {}}) async {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  print("----- Sentry Intercepted error: $error -----");
 | 
					  print("----- Sentry Intercepted error: $error -----");
 | 
				
			||||||
  print(stackTrace);
 | 
					  print(stackTrace);
 | 
				
			||||||
@@ -167,10 +167,14 @@ Future<void> sentryReportError(dynamic error, dynamic stackTrace) async {
 | 
				
			|||||||
  final app_info = await getAppInfo();
 | 
					  final app_info = await getAppInfo();
 | 
				
			||||||
  final device_info = await getDeviceInfo();
 | 
					  final device_info = await getDeviceInfo();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Ensure we pass the 'source' of the error
 | 
				
			||||||
 | 
					  context["source"] = source;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Sentry.configureScope((scope) {
 | 
					  Sentry.configureScope((scope) {
 | 
				
			||||||
    scope.setExtra("server", server_info);
 | 
					    scope.setExtra("server", server_info);
 | 
				
			||||||
    scope.setExtra("app", app_info);
 | 
					    scope.setExtra("app", app_info);
 | 
				
			||||||
    scope.setExtra("device", device_info);
 | 
					    scope.setExtra("device", device_info);
 | 
				
			||||||
 | 
					    scope.setExtra("context", context);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Sentry.captureException(error, stackTrace: stackTrace).catchError((error) {
 | 
					  Sentry.captureException(error, stackTrace: stackTrace).catchError((error) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,15 @@ Future<void> main() async {
 | 
				
			|||||||
    FlutterError.onError = (FlutterErrorDetails details) async {
 | 
					    FlutterError.onError = (FlutterErrorDetails details) async {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Ensure that the error gets reported to sentry!
 | 
					      // 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(
 | 
					    runApp(
 | 
				
			||||||
@@ -47,7 +55,7 @@ Future<void> main() async {
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  }, (Object error, StackTrace stackTrace) async {
 | 
					  }, (Object error, StackTrace stackTrace) async {
 | 
				
			||||||
    sentryReportError(error, stackTrace);
 | 
					    sentryReportError("main.runZonedGuarded", error, stackTrace);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,7 +86,10 @@ class PaginatedSearchState<T extends StatefulWidget> extends State<T> {
 | 
				
			|||||||
    } catch (error, stackTrace) {
 | 
					    } catch (error, stackTrace) {
 | 
				
			||||||
      _pagingController.error = error;
 | 
					      _pagingController.error = error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      sentryReportError(error, stackTrace);
 | 
					      sentryReportError(
 | 
				
			||||||
 | 
					        "paginator.fetchPage",
 | 
				
			||||||
 | 
					        error, stackTrace,
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user