Code shuffle
Summary: Moved a lot of utility logic in separate files for Android and iOS, to make cleanup in next diffs easier by having a bit smaller files. Purely a code shuffle, no functional changes Reviewed By: passy Differential Revision: D28102399 fbshipit-source-id: 2fd8f6669bdd2804fa8a7e1791c610ae7883eda6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c0633652e8
commit
01ea822341
48
desktop/plugins/public/crash_reporter/crash-utils.tsx
Normal file
48
desktop/plugins/public/crash_reporter/crash-utils.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import unicodeSubstring from 'unicode-substring';
|
||||
import type {CrashLog} from './index';
|
||||
import {parseAndroidCrash} from './android-crash-utils';
|
||||
import {parseIosCrash} from './ios-crash-utils';
|
||||
|
||||
export const UNKNOWN_CRASH_REASON = 'Cannot figure out the cause';
|
||||
|
||||
export function parseCrashLog(
|
||||
content: string,
|
||||
os: string,
|
||||
logDate?: Date,
|
||||
): CrashLog {
|
||||
const fallbackReason = UNKNOWN_CRASH_REASON;
|
||||
switch (os) {
|
||||
case 'iOS': {
|
||||
return parseIosCrash(content, fallbackReason, logDate);
|
||||
}
|
||||
case 'Android': {
|
||||
return parseAndroidCrash(content, fallbackReason, logDate);
|
||||
}
|
||||
default: {
|
||||
throw new Error('Unsupported OS');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function truncate(baseString: string, numOfChars: number): string {
|
||||
if (baseString.length <= numOfChars) {
|
||||
return baseString;
|
||||
}
|
||||
const truncated_string = unicodeSubstring(baseString, 0, numOfChars - 1);
|
||||
return truncated_string + '\u2026';
|
||||
}
|
||||
|
||||
export function trimCallStackIfPossible(callstack: string): string {
|
||||
const regex = /Application Specific Information:/;
|
||||
const query = regex.exec(callstack);
|
||||
return query ? callstack.substring(0, query.index) : callstack;
|
||||
}
|
||||
Reference in New Issue
Block a user