Limit the message length in the notification
Summary:
Before this diff the notification fired for crash reporter had the entire callstack as its message, which is actually not required and it also makes a UI not good.
This diff just limits the message length
BUG:
{F154537911}
Reviewed By: passy
Differential Revision: D14594189
fbshipit-source-id: 663710e3e80be4367d0cc2a532fd4aa312cc0c1e
This commit is contained in:
committed by
Facebook Github Bot
parent
de46240272
commit
c422829beb
14
flow-typed/npm/unicode-substring.js
vendored
Normal file
14
flow-typed/npm/unicode-substring.js
vendored
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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<Notification> => {
|
||||
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,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -10,5 +10,8 @@
|
||||
"bugs": {
|
||||
"email": "prit91@fb.com",
|
||||
"url": "https://fb.workplace.com/groups/220760072184928/"
|
||||
},
|
||||
"dependencies": {
|
||||
"unicode-substring": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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==
|
||||
|
||||
Reference in New Issue
Block a user