2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Add extra context information to sentry error reports

- Should help to track down bugs where stacktrace is missing information
- Adds some more error catching, too
This commit is contained in:
Oliver Walters 2022-05-12 22:46:12 +10:00
parent e47d88a4bb
commit c90a849a5a
5 changed files with 69 additions and 13 deletions

View File

@ -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();
}

View File

@ -788,7 +788,14 @@ Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> 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<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lo
print(error.toString());
// Report the error
sentryReportError(error, stacktrace);
sentryReportError(
"apiForm.extractFieldDefinition : as map",
error, stacktrace,
context: {
"el": el.toString(),
}
);
return {};
}

View File

@ -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(stackTrace);
@ -167,10 +167,14 @@ Future<void> 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) {

View File

@ -39,7 +39,15 @@ Future<void> 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<void> main() async {
);
}, (Object error, StackTrace stackTrace) async {
sentryReportError(error, stackTrace);
sentryReportError("main.runZonedGuarded", error, stackTrace);
});
}

View File

@ -86,7 +86,10 @@ class PaginatedSearchState<T extends StatefulWidget> extends State<T> {
} catch (error, stackTrace) {
_pagingController.error = error;
sentryReportError(error, stackTrace);
sentryReportError(
"paginator.fetchPage",
error, stackTrace,
);
}
}