Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/error handler #141

Merged
merged 4 commits into from Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions __Mocks__/index.js
Expand Up @@ -152,6 +152,15 @@ jest.mock('@react-native-community/async-storage', () => ({
}))
}));


jest.mock('react-native-exception-handler', () => ({
setJSExceptionHandler: jest.fn((callback) => callback({
message: 'test'
}, true)),
setNativeExceptionHandler: jest.fn((callback) => callback('data'))
}));


jest.doMock('react-native', () =>
// Extend ReactNative
Object.setPrototypeOf(
Expand Down
7 changes: 7 additions & 0 deletions android/app/src/main/java/DeviceInfo/DeviceInfoModule.java
Expand Up @@ -117,4 +117,11 @@ public void getIpv6(Promise promise) {

promise.resolve(array);
}

/**
* close the app completely
*/
@ReactMethod public void exitApp(){
System.exit(0);
}
}
1 change: 0 additions & 1 deletion android/app/src/main/java/DeviceInfo/Utils.java
Expand Up @@ -154,7 +154,6 @@ public static String getOurVersion(Context ctx) {
}



public static List<String> getAllIps() {
List<String> ipv4Array = new ArrayList<String>();
try {
Expand Down
Expand Up @@ -5,6 +5,7 @@


import com.facebook.react.ReactApplication;
import com.masteratul.exceptionhandler.ReactNativeExceptionHandlerPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
Expand Down Expand Up @@ -37,7 +38,6 @@ protected List<ReactPackage> getPackages() {
packages.add(new LochaP2PPackage());
packages.add(new CoapClientPackage());
packages.add(new LocalNotificationPackage());

return packages;
}

Expand Down
27 changes: 23 additions & 4 deletions android/app/src/test/java/DeviceInfo/UtilsTest.java
@@ -1,33 +1,50 @@
package DeviceInfo;


import android.app.Activity;
import android.content.pm.PackageManager;

import androidx.annotation.NonNull;
import androidx.test.core.app.ApplicationProvider;

import com.facebook.common.util.Hex;
import com.facebook.react.bridge.ReactApplicationContext;

import org.junit.Before;

import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;

import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.io.UnsupportedEncodingException;

import static org.junit.jupiter.api.Assertions.*;


@Config(sdk = 28)
@RunWith(RobolectricTestRunner.class)
class UtilsTest {

private ReactApplicationContext context;
private static final String TEST = "test";

@Mock
private PackageManager mockPackageManager;


@Before
public void setUp(){
context = getRNContext();
when(context.getPackageManager()).thenReturn(mockPackageManager);
}

@NonNull
private ReactApplicationContext getRNContext() {
return new ReactApplicationContext(ApplicationProvider.getApplicationContext());
}

@Test
public void noNullInstance(){
Utils utils = new Utils();
Expand Down Expand Up @@ -55,9 +72,11 @@ void getUTF8Bytes() throws UnsupportedEncodingException {

@Test
void hexStringToByteArray() {

xkevin190 marked this conversation as resolved.
Show resolved Hide resolved
byte[] bytes = Utils.hexStringToByteArray(TEST);
String result = new String(bytes);
String expected = new String(bytes);
assertEquals(result, expected);
}

}
2 changes: 2 additions & 0 deletions android/settings.gradle
@@ -1,4 +1,6 @@
rootProject.name = 'LochaMeshChat'
include ':react-native-exception-handler'
project(':react-native-exception-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exception-handler/android')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

include ':react-native-permissions'
Expand Down
43 changes: 37 additions & 6 deletions ios/LochaMeshChat.xcodeproj/project.pbxproj
Expand Up @@ -105,6 +105,7 @@
393FDF0FAD2140EF939F4FD2 /* rubicon-icon-font.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 6F29542D6E354A7B90D1BA36 /* rubicon-icon-font.ttf */; };
D4A278A3A7804C1E99DBFEDF /* SimpleLineIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C805A58D905A4229872AD27C /* SimpleLineIcons.ttf */; };
B7DC39FCD2084AD28B757C7C /* Zocial.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 670C3CB401294816BBF4147D /* Zocial.ttf */; };
8BFF8C4D212C4B10B47F9157 /* libReactNativeExceptionHandler.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DC5796CE1FD4896ABCC2DD1 /* libReactNativeExceptionHandler.a */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -689,6 +690,8 @@
6F29542D6E354A7B90D1BA36 /* rubicon-icon-font.ttf */ = {isa = PBXFileReference; name = "rubicon-icon-font.ttf"; path = "../node_modules/native-base/Fonts/rubicon-icon-font.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
C805A58D905A4229872AD27C /* SimpleLineIcons.ttf */ = {isa = PBXFileReference; name = "SimpleLineIcons.ttf"; path = "../node_modules/native-base/Fonts/SimpleLineIcons.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
670C3CB401294816BBF4147D /* Zocial.ttf */ = {isa = PBXFileReference; name = "Zocial.ttf"; path = "../node_modules/native-base/Fonts/Zocial.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
59648AB5197342E680472593 /* ReactNativeExceptionHandler.xcodeproj */ = {isa = PBXFileReference; name = "ReactNativeExceptionHandler.xcodeproj"; path = "../node_modules/react-native-exception-handler/ios/ReactNativeExceptionHandler.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
7DC5796CE1FD4896ABCC2DD1 /* libReactNativeExceptionHandler.a */ = {isa = PBXFileReference; name = "libReactNativeExceptionHandler.a"; path = "libReactNativeExceptionHandler.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -740,6 +743,7 @@
23BFE7977456443F9A95CCAA /* libRNCAsyncStorage.a in Frameworks */,
343506C412CD4AB2A36EA1D1 /* libRNFetchBlob.a in Frameworks */,
6E8C798B6348428FB6DC70A5 /* libRNPermissions.a in Frameworks */,
8BFF8C4D212C4B10B47F9157 /* libReactNativeExceptionHandler.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1167,6 +1171,7 @@
891BE6F713C14A87BCA233E0 /* RNCAsyncStorage.xcodeproj */,
8B10E40556784990B9991F75 /* RNFetchBlob.xcodeproj */,
1E78ADE15D694285A5BE9A51 /* RNPermissions.xcodeproj */,
59648AB5197342E680472593 /* ReactNativeExceptionHandler.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
Expand Down Expand Up @@ -2171,11 +2176,15 @@
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
"$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**",
"$(SRCROOT)/../node_modules/react-native-permissions/ios/**",
"$(SRCROOT)/../node_modules/react-native-exception-handler/ios",
);
INFOPLIST_FILE = LochaMeshChatTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
Expand Down Expand Up @@ -2220,11 +2229,15 @@
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
"$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**",
"$(SRCROOT)/../node_modules/react-native-permissions/ios/**",
"$(SRCROOT)/../node_modules/react-native-exception-handler/ios",
);
INFOPLIST_FILE = LochaMeshChatTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
Expand Down Expand Up @@ -2270,6 +2283,7 @@
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
"$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**",
"$(SRCROOT)/../node_modules/react-native-permissions/ios/**",
"$(SRCROOT)/../node_modules/react-native-exception-handler/ios",
);
INFOPLIST_FILE = LochaMeshChat/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down Expand Up @@ -2321,6 +2335,7 @@
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
"$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**",
"$(SRCROOT)/../node_modules/react-native-permissions/ios/**",
"$(SRCROOT)/../node_modules/react-native-exception-handler/ios",
);
INFOPLIST_FILE = LochaMeshChat/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down Expand Up @@ -2377,10 +2392,14 @@
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
"$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**",
"$(SRCROOT)/../node_modules/react-native-permissions/ios/**",
"$(SRCROOT)/../node_modules/react-native-exception-handler/ios",
);
INFOPLIST_FILE = "LochaMeshChat-tvOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
Expand Down Expand Up @@ -2433,10 +2452,14 @@
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
"$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**",
"$(SRCROOT)/../node_modules/react-native-permissions/ios/**",
"$(SRCROOT)/../node_modules/react-native-exception-handler/ios",
);
INFOPLIST_FILE = "LochaMeshChat-tvOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
Expand Down Expand Up @@ -2488,10 +2511,14 @@
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
"$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**",
"$(SRCROOT)/../node_modules/react-native-permissions/ios/**",
"$(SRCROOT)/../node_modules/react-native-exception-handler/ios",
);
INFOPLIST_FILE = "LochaMeshChat-tvOSTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
Expand Down Expand Up @@ -2543,10 +2570,14 @@
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
"$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**",
"$(SRCROOT)/../node_modules/react-native-permissions/ios/**",
"$(SRCROOT)/../node_modules/react-native-exception-handler/ios",
);
INFOPLIST_FILE = "LochaMeshChat-tvOSTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
Expand Down
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -12,7 +12,8 @@
"lint": "eslint '**/*.{js,jsx}' --quiet",
"test": "jest --verbose --runInBand --detectOpenHandles --forceExit && codecov",
"release": "cd android && ./gradlew assembleRelease",
"keystore": "cd android && ./keystore.sh"
"keystore": "cd android && ./keystore.sh",
"debugRelease": "react-native run-android --variant=release"
},
"precommit": "lint --staged",
"dependencies": {
Expand Down Expand Up @@ -52,6 +53,7 @@
"react-native-camera": "^3.23.1",
"react-native-document-picker": "^3.2.4",
"react-native-drawer": "^2.5.1",
"react-native-exception-handler": "^2.10.8",
"react-native-fs": "^2.16.6",
"react-native-gesture-handler": "^1.6.1",
"react-native-image-crop-picker": "^0.24.1",
Expand Down Expand Up @@ -189,4 +191,4 @@
"_stream_passthrough": "readable-stream/passthrough",
"fs": "react-native-level-fs"
}
}
}
4 changes: 2 additions & 2 deletions src/components/Drawer.js
Expand Up @@ -7,16 +7,16 @@ import {
Button,
Icon,
Thumbnail,
BackAndroid
} from 'native-base';
import {
View, Text, StyleSheet, NativeModules
View, Text, StyleSheet, NativeModules, Alert
} from 'react-native';
import { connect } from 'react-redux';
import { closeMenu, openAdministrativePanel, isAdministrative } from '../store/aplication/aplicationAction';
import { images } from '../utils/constans';
import { toast } from '../utils/utils';


/**
* view of the menu drawer
* @class HeaderComponent
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -6,7 +6,7 @@ import Home from './views/home';
import LoadWallet from './views/LoadWallet';
import RestoreWithPing from './views/LoadWallet/RestoreWithPin';
import { selectedChat } from './store/chats';

import './utils/ErrorHandler';
/**
*
* @description application views container
Expand Down
32 changes: 32 additions & 0 deletions src/utils/ErrorHandler.js
@@ -0,0 +1,32 @@

import { Alert, NativeModules } from 'react-native';
import { setJSExceptionHandler, setNativeExceptionHandler } from 'react-native-exception-handler';
import { chatService } from '../../App';
const device = NativeModules.RNDeviceInfo;

const errorHandler = (e, isFatal) => {
if (isFatal) {
Alert.alert(
'An error has occurred',
`An unexpected fatal error has occurred, it is necessary to restart the application.

it's this is caused by: ${e.message}
`,
[{
text: 'Ok',
onPress: () => {
chatService.stop().then(
() => { device.exitApp(); }
);
}
}]
);
}
};

setJSExceptionHandler(errorHandler, true);


setNativeExceptionHandler((dataString) => {
console.warn(dataString);
});
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -8157,6 +8157,11 @@ react-native-easy-grid@0.2.2:
dependencies:
lodash "^4.17.15"

react-native-exception-handler@^2.10.8:
version "2.10.8"
resolved "https://registry.yarnpkg.com/react-native-exception-handler/-/react-native-exception-handler-2.10.8.tgz#1a7f846592d888d23adaf797e31802585f1d9ff0"
integrity sha512-ZN+jwpADRkCUNdad/50k0mZdMoICGrGdtaxgvRU+pNcWRRBAXJhuo4+jY0eQaoVpx1ghycGE6tBu9ka8gL2NOQ==

react-native-fs@^2.16.6:
version "2.16.6"
resolved "https://registry.yarnpkg.com/react-native-fs/-/react-native-fs-2.16.6.tgz#2901789a43210a35a0ef0a098019bbef3af395fd"
Expand Down