diff --git a/.github/workflows/validate-cpp.yml b/.github/workflows/validate-cpp.yml index ab016aa..fd3a32f 100644 --- a/.github/workflows/validate-cpp.yml +++ b/.github/workflows/validate-cpp.yml @@ -31,4 +31,5 @@ jobs: ,-build/namespaces\ ,-whitespace/comments\ ,-build/include_order\ + ,-build/c++11\ " diff --git a/android/src/main/cpp/CameraView.cpp b/android/src/main/cpp/CameraView.cpp index bb6733c..665bd31 100644 --- a/android/src/main/cpp/CameraView.cpp +++ b/android/src/main/cpp/CameraView.cpp @@ -6,9 +6,11 @@ #include #include +#include #include #include +#include namespace vision { @@ -36,9 +38,12 @@ void CameraView::frameProcessorCallback(const alias_ref try { frameProcessor_(frame); - } catch (const std::exception& exception) { + } catch (const jsi::JSError& error) { // TODO: jsi::JSErrors cannot be caught on Hermes. They crash the entire app. - __android_log_print(ANDROID_LOG_ERROR, TAG, "Frame Processor threw an error! %s", exception.what()); + auto stack = std::regex_replace(error.getStack(), std::regex("\n"), "\n "); + __android_log_print(ANDROID_LOG_ERROR, TAG, "Frame Processor threw an error! %s\nIn: %s", error.getMessage().c_str(), stack.c_str()); + } catch (const std::exception& exception) { + __android_log_print(ANDROID_LOG_ERROR, TAG, "Frame Processor threw a C++ error! %s", exception.what()); } } diff --git a/ios/Frame Processor/FrameProcessorUtils.mm b/ios/Frame Processor/FrameProcessorUtils.mm index 6f0fac8..25daa3e 100644 --- a/ios/Frame Processor/FrameProcessorUtils.mm +++ b/ios/Frame Processor/FrameProcessorUtils.mm @@ -9,6 +9,7 @@ #import "FrameProcessorUtils.h" #import #import +#import #import "FrameHostObject.h" #import "Frame.h" @@ -18,7 +19,7 @@ #import "JSConsoleHelper.h" #import -FrameProcessorCallback convertJSIFunctionToFrameProcessorCallback(jsi::Runtime &runtime, const jsi::Function &value) { +FrameProcessorCallback convertJSIFunctionToFrameProcessorCallback(jsi::Runtime& runtime, const jsi::Function& value) { __block auto cb = value.getFunction(runtime); return ^(Frame* frame) { @@ -27,15 +28,17 @@ FrameProcessorCallback convertJSIFunctionToFrameProcessorCallback(jsi::Runtime & try { cb.callWithThis(runtime, cb, jsi::Object::createFromHostObject(runtime, frameHostObject)); } catch (jsi::JSError& jsError) { - auto message = jsError.getMessage(); + auto stack = std::regex_replace(jsError.getStack(), std::regex("\n"), "\n "); + auto message = [NSString stringWithFormat:@"Frame Processor threw an error: %s\nIn: %s", jsError.getMessage().c_str(), stack.c_str()]; + RCTBridge* bridge = [RCTBridge currentBridge]; if (bridge != nil) { bridge.jsCallInvoker->invokeAsync([bridge, message]() { auto logFn = [JSConsoleHelper getLogFunctionForBridge:bridge]; - logFn(RCTLogLevelError, [NSString stringWithFormat:@"Frame Processor threw an error: %s", message.c_str()]); + logFn(RCTLogLevelError, message); }); } else { - NSLog(@"Frame Processor threw an error: %s", message.c_str()); + NSLog(@"%@", message); } } diff --git a/scripts/cpplint.sh b/scripts/cpplint.sh index fc2479b..bc7ef05 100755 --- a/scripts/cpplint.sh +++ b/scripts/cpplint.sh @@ -1,7 +1,7 @@ #!/bin/bash if which cpplint >/dev/null; then - cpplint --linelength=230 --filter=-legal/copyright,-readability/todo,-build/namespaces,-whitespace/comments,-build/include_order --quiet --recursive --exclude "android/src/main/cpp/reanimated-headers" cpp android/src/main/cpp + cpplint --linelength=230 --filter=-legal/copyright,-readability/todo,-build/namespaces,-whitespace/comments,-build/include_order,-build/c++11 --quiet --recursive --exclude "android/src/main/cpp/reanimated-headers" cpp android/src/main/cpp else echo "warning: cpplint not installed, download from https://github.com/cpplint/cpplint" fi