diff --git a/flow-typed/npm/unicode-substring.js b/flow-typed/npm/unicode-substring.js new file mode 100644 index 000000000..8bba10d04 --- /dev/null +++ b/flow-typed/npm/unicode-substring.js @@ -0,0 +1,14 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + * @flow + */ +declare module 'unicode-substring' { + declare export default function unicodeSubstring( + baseString: string, + start: number, + end: number, + ): string; +} diff --git a/src/plugins/crash_reporter/index.js b/src/plugins/crash_reporter/index.js index 996e6ac42..e7888971a 100644 --- a/src/plugins/crash_reporter/index.js +++ b/src/plugins/crash_reporter/index.js @@ -28,6 +28,7 @@ import { Spacer, Select, } from 'flipper'; +import unicodeSubstring from 'unicode-substring'; import fs from 'fs'; import os from 'os'; import util from 'util'; @@ -313,6 +314,14 @@ export function parseCrashLog( } } +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 parsePath(content: string): ?string { const regex = /Path: *[\w\-\/\.\t\ \_\%]*\n/; const arr = regex.exec(content); @@ -511,11 +520,19 @@ export default class CrashReporterPlugin extends FlipperDevicePlugin< ): Array => { return persistedState.crashes.map((crash: Crash) => { const id = crash.notificationID; + const title = `CRASH: ${truncate(crash.name, 50)} Reason: ${truncate( + crash.reason, + 50, + )}`; + const callstack = CrashReporterPlugin.trimCallStackIfPossible( + crash.callstack, + ); + const msg = `Callstack: ${truncate(callstack, 200)}`; return { id, - message: CrashReporterPlugin.trimCallStackIfPossible(crash.callstack), + message: msg, severity: 'error', - title: 'CRASH: ' + crash.name + ' ' + crash.reason, + title: title, action: id, }; }); diff --git a/src/plugins/crash_reporter/package.json b/src/plugins/crash_reporter/package.json index 800d1e880..11d34e964 100644 --- a/src/plugins/crash_reporter/package.json +++ b/src/plugins/crash_reporter/package.json @@ -10,5 +10,8 @@ "bugs": { "email": "prit91@fb.com", "url": "https://fb.workplace.com/groups/220760072184928/" + }, + "dependencies": { + "unicode-substring": "^1.0.0" } } diff --git a/src/plugins/crash_reporter/yarn.lock b/src/plugins/crash_reporter/yarn.lock index fb57ccd13..72ab292c7 100644 --- a/src/plugins/crash_reporter/yarn.lock +++ b/src/plugins/crash_reporter/yarn.lock @@ -2,3 +2,7 @@ # yarn lockfile v1 +unicode-substring@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unicode-substring/-/unicode-substring-1.0.0.tgz#659fb839078e7bee84b86c27210ac4db215bf885" + integrity sha512-2acGIOTaqS/GWocwKdyL1Vk9MHglCss1mR0CL2o/YJTwKrAt6JbTrw4X187VkSDmFcpJ8n2i3/+gJSYEdvXJMg==