Skip to content

Commit

Permalink
chore(core): guard check oversize trace (facebook#121)
Browse files Browse the repository at this point in the history
Summary:
OSS ticket:
facebook#121

Reviewed By: twobassdrum

Differential Revision: D59178943

fbshipit-source-id: 3ad7870b3cb46d0fa52ff8fdae5c6eb38190aa99
  • Loading branch information
JacksonGL authored and facebook-github-bot committed Jun 29, 2024
1 parent 16b4d9a commit b9d793e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/core/src/logger/LeakTraceDetailsLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 19,7 @@ import serializer from '../lib/Serializer';
import utils from '../lib/Utils';
import fs from 'fs';
import path from 'path';
import info from '../lib/Console';

class LeakTraceDetailsLogger {
_wrapPathJSONInLoader(jsonContent: string): string {
Expand All @@ -41,11 42,22 @@ class LeakTraceDetailsLogger {
): Nullable<ISerializedInfo> {
const options = {leakedIdSet, nodeIdsInSnapshots};
const gcTrace = serializer.JSONifyPath(trace, snapshot, options);
const traceJSON = JSON.stringify(gcTrace, null, 2);
const content = this._wrapPathJSONInLoader(traceJSON);
fs.writeFile(filepath, content, 'UTF-8', () => {
// noop
});
try {
const traceJSON = JSON.stringify(gcTrace, null, 2);
const content = this._wrapPathJSONInLoader(traceJSON);
fs.writeFile(filepath, content, 'UTF-8', () => {
// noop
});
} catch (ex) {
const error = utils.getError(ex);
if (error.message.includes('Invalid string length')) {
info.warning(
'Trace details JSON not saved because it exceeded the size limit.',
);
} else {
utils.haltOrThrow(error);
}
}
return gcTrace;
}

Expand Down

0 comments on commit b9d793e

Please sign in to comment.