From 4f6de3d1efe39762217f53d43b351437aabb8411 Mon Sep 17 00:00:00 2001 From: Liang Gong Date: Fri, 30 Aug 2024 16:45:35 -0700 Subject: [PATCH] chore(analysis): adjust memlab analyze object error message Summary: Better error message for the `memlab analyze object` command in case no `--node-id` flag is provided Reviewed By: twobassdrum Differential Revision: D61983870 fbshipit-source-id: d4ac206f726505db31b6dae0dc160455a714bcf7 --- .../src/plugins/ObjectContentAnalysis.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/heap-analysis/src/plugins/ObjectContentAnalysis.ts b/packages/heap-analysis/src/plugins/ObjectContentAnalysis.ts index b1b0539b..13d30fed 100644 --- a/packages/heap-analysis/src/plugins/ObjectContentAnalysis.ts +++ b/packages/heap-analysis/src/plugins/ObjectContentAnalysis.ts @@ -19,7 +19,7 @@ import BaseAnalysis from '../BaseAnalysis'; import pluginUtils from '../PluginUtils'; import OutputOption from '../options/HeapAnalysisOutputOption'; -class GlobalVariableAnalysis extends BaseAnalysis { +export default class ObjectContentAnalysis extends BaseAnalysis { getCommandName(): string { return 'object'; } @@ -36,12 +36,15 @@ class GlobalVariableAnalysis extends BaseAnalysis { /** @internal */ async process(options: HeapAnalysisOptions): Promise { - const snapshot = await pluginUtils.loadHeapSnapshot(options); const nodeId = config.focusFiberNodeId; + if (nodeId < 0) { + utils.haltOrThrow('Specify an object by --node-id'); + return; + } + const snapshot = await pluginUtils.loadHeapSnapshot(options); const node = snapshot.getNodeById(nodeId); if (!node) { - info.error(`Object @${nodeId} is not found.`); - info.lowLevel(`Specify an object by --node-id`); + utils.haltOrThrow(`Object @${nodeId} is not found.`); return; } @@ -119,5 +122,3 @@ class GlobalVariableAnalysis extends BaseAnalysis { return ret; } } - -export default GlobalVariableAnalysis;