Don't send notifications for crashes we can't explain

Summary: If the `crash.reason` assumes the default value of "Cannot figure out the cause", we don't show a notification in the hub. The crash is still visible in the Crash plugin, but the superfluous Reason row is hidden there, as we can't say anything useful there anyways

Reviewed By: passy

Differential Revision: D18223910

fbshipit-source-id: c033085badbf633b58f95c495c6d3a22bc7fb163
This commit is contained in:
Gijs Weterings
2019-10-30 08:33:08 -07:00
committed by Facebook Github Bot
parent d0ab63297f
commit 7e374ebdf1

View File

@@ -176,6 +176,8 @@ const StackTraceContainer = styled(FlexColumn)({
flexShrink: 0, flexShrink: 0,
}); });
const UNKNOWN_CRASH_REASON = 'Cannot figure out the cause';
export function getNewPersisitedStateFromCrashLog( export function getNewPersisitedStateFromCrashLog(
persistedState: ?PersistedState, persistedState: ?PersistedState,
persistingPlugin: Class<FlipperDevicePlugin<> | FlipperPlugin<>>, persistingPlugin: Class<FlipperDevicePlugin<> | FlipperPlugin<>>,
@@ -265,7 +267,7 @@ export function parseCrashLog(
os: OS, os: OS,
logDate: ?Date, logDate: ?Date,
): CrashLog { ): CrashLog {
const stubString = 'Cannot figure out the cause'; const fallbackReason = UNKNOWN_CRASH_REASON;
switch (os) { switch (os) {
case 'iOS': { case 'iOS': {
const regex = /Exception Type: *[\w]*/; const regex = /Exception Type: *[\w]*/;
@@ -273,8 +275,7 @@ export function parseCrashLog(
const exceptionString = arr ? arr[0] : ''; const exceptionString = arr ? arr[0] : '';
const exceptionRegex = /[\w]*$/; const exceptionRegex = /[\w]*$/;
const tmp = exceptionRegex.exec(exceptionString); const tmp = exceptionRegex.exec(exceptionString);
const exception = const exception = tmp && tmp[0].length ? tmp[0] : fallbackReason;
tmp && tmp[0].length ? tmp[0] : 'Cannot figure out the cause';
let date = logDate; let date = logDate;
if (!date) { if (!date) {
@@ -299,7 +300,7 @@ export function parseCrashLog(
case 'Android': { case 'Android': {
const regForName = /.*\n/; const regForName = /.*\n/;
const nameRegArr = regForName.exec(content); const nameRegArr = regForName.exec(content);
let name = nameRegArr ? nameRegArr[0] : stubString; let name = nameRegArr ? nameRegArr[0] : fallbackReason;
const regForCallStack = /\tat[\w\s\n.$&+,:;=?@#|'<>.^*()%!-]*$/; const regForCallStack = /\tat[\w\s\n.$&+,:;=?@#|'<>.^*()%!-]*$/;
const callStackArray = regForCallStack.exec(content); const callStackArray = regForCallStack.exec(content);
const callStack = callStackArray ? callStackArray[0] : ''; const callStack = callStackArray ? callStackArray[0] : '';
@@ -311,7 +312,7 @@ export function parseCrashLog(
const reason = const reason =
remainingString.length > 0 remainingString.length > 0
? remainingString.split('\n').pop() ? remainingString.split('\n').pop()
: stubString; : fallbackReason;
if (name[name.length - 1] === '\n') { if (name[name.length - 1] === '\n') {
name = name.slice(0, -1); name = name.slice(0, -1);
} }
@@ -558,10 +559,11 @@ export default class CrashReporterPlugin extends FlipperDevicePlugin<
): Array<Notification> => { ): Array<Notification> => {
const filteredCrashes = persistedState.crashes.filter(crash => { const filteredCrashes = persistedState.crashes.filter(crash => {
const ignore = !crash.name && !crash.reason; const ignore = !crash.name && !crash.reason;
if (ignore) { const unknownCrashCause = crash.reason === UNKNOWN_CRASH_REASON;
if (ignore || unknownCrashCause) {
console.error('Ignored the notification for the crash', crash); console.error('Ignored the notification for the crash', crash);
} }
return !ignore; return !ignore && !unknownCrashCause;
}); });
return filteredCrashes.map((crash: Crash) => { return filteredCrashes.map((crash: Crash) => {
const id = crash.notificationID; const id = crash.notificationID;
@@ -717,6 +719,7 @@ export default class CrashReporterPlugin extends FlipperDevicePlugin<
selectedCrashID, selectedCrashID,
onCrashChange, onCrashChange,
}; };
const showReason = crash.reason !== UNKNOWN_CRASH_REASON;
return ( return (
<FlexColumn> <FlexColumn>
{this.device.os == 'Android' ? ( {this.device.os == 'Android' ? (
@@ -733,7 +736,9 @@ export default class CrashReporterPlugin extends FlipperDevicePlugin<
)} )}
<ScrollableColumn> <ScrollableColumn>
<HeaderRow title="Name" value={crash.name} /> <HeaderRow title="Name" value={crash.name} />
<HeaderRow title="Reason" value={crash.reason} /> {showReason ? (
<HeaderRow title="Reason" value={crash.reason} />
) : null}
<Padder paddingLeft={8} paddingTop={4} paddingBottom={2}> <Padder paddingLeft={8} paddingTop={4} paddingBottom={2}>
<Title> Stacktrace </Title> <Title> Stacktrace </Title>
</Padder> </Padder>