diff --git a/src/Main/sentryIntegration.cxx b/src/Main/sentryIntegration.cxx index f7872a6c7..e116a2a79 100644 --- a/src/Main/sentryIntegration.cxx +++ b/src/Main/sentryIntegration.cxx @@ -101,6 +101,35 @@ void addSentryTag(const char* tag, const char* value) sentry_set_tag(tag, value); } +void sentryReportNasalError(const std::string& msg, const string_list& stack) +{ + if (!static_sentryEnabled) + return; +#if 0 + sentry_value_t exc = sentry_value_new_object(); + sentry_value_set_by_key(exc, "type", sentry_value_new_string("Exception")); + sentry_value_set_by_key(exc, "value", sentry_value_new_string(msg.c_str())); + + sentry_value_t stackData = sentry_value_new_list(); + for (const auto& nasalFrame : stack) { + sentry_value_append(stackData, sentry_value_new_string(nasalFrame.c_str())); + } + sentry_value_set_by_key(exc, "stack", stackData); + + + sentry_value_t event = sentry_value_new_event(); + sentry_value_set_by_key(event, "exception", exc); + + // add the Nasal stack trace data + + // capture the C++ stack-trace. Probably not that useful but can't hurt + sentry_event_value_add_stacktrace(event, nullptr, 0); + + sentry_capture_event(event); + +#endif +} + } // of namespace #else @@ -131,6 +160,10 @@ void addSentryTag(const char*, const char*) { } +void sentryReportNasalError(const std::string&, const string_list&) +{ +} + } // of namespace #endif diff --git a/src/Main/sentryIntegration.hxx b/src/Main/sentryIntegration.hxx index e1be9c0c4..5b4d6cfe2 100644 --- a/src/Main/sentryIntegration.hxx +++ b/src/Main/sentryIntegration.hxx @@ -19,6 +19,7 @@ #pragma once #include +#include namespace flightgear { @@ -34,6 +35,7 @@ void addSentryTag(const char* tag, const char* value); void addSentryTag(const std::string& tag, const std::string& value); +void sentryReportNasalError(const std::string& msg, const string_list& stack); } // of namespace flightgear diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index bd1819127..288a25760 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -55,6 +55,7 @@ #include
#include
#include
+#include
using std::map; using std::string; @@ -310,7 +311,9 @@ naRef FGNasalSys::callMethodWithContext(naContext ctx, naRef code, naRef self, i return naCallMethodCtx(ctx, code, self, argc, args, locals); } catch (sg_exception& e) { SG_LOG(SG_NASAL, SG_DEV_ALERT, "caught exception invoking nasal method:" << e.what()); - logNasalStack(ctx); + string_list nasalStack; + logNasalStack(ctx, nasalStack); + flightgear::sentryReportNasalError(string{"Exception invoking nasal method:"} + e.what(), nasalStack); return naNil(); } } @@ -1305,23 +1308,34 @@ void FGNasalSys::loadPropertyScripts(SGPropertyNode* n) // Logs a runtime error, with stack trace, to the FlightGear log stream void FGNasalSys::logError(naContext context) { - SG_LOG(SG_NASAL, SG_ALERT, "Nasal runtime error: " << naGetError(context)); - logNasalStack(context); + string errorMessage = naGetError(context); + SG_LOG(SG_NASAL, SG_ALERT, "Nasal runtime error: " << errorMessage); + + string_list nasalStack; + logNasalStack(context, nasalStack); + flightgear::sentryReportNasalError(errorMessage, nasalStack); } -void FGNasalSys::logNasalStack(naContext context) +void FGNasalSys::logNasalStack(naContext context, string_list& stack) { const int stack_depth = naStackDepth(context); if (stack_depth < 1) return; + stack.push_back(string{naStr_data(naGetSourceFile(context, 0))} + + ", line " + std::to_string(naGetLine(context, 0))); + SG_LOG(SG_NASAL, SG_ALERT, " at " << naStr_data(naGetSourceFile(context, 0)) << ", line " << naGetLine(context, 0)); + for(int i=1; i