From 7090e73031f853afb459f87bf4fa67a7bfe1f846 Mon Sep 17 00:00:00 2001 From: Hugh Cunningham <57735705+hughy@users.noreply.github.com> Date: Fri, 10 Mar 2023 21:13:32 -0800 Subject: [PATCH] improves output of stop command (#3641) the 'stopNode' RPC shuts down the node before returning a response, so the cli client receives an error from the lost connection. IronfishCommand handles RPC connection errors and outputs 'Cannot connect to your node, start your node first.'. this is confusing both because we were able to connect to the node and because we successfully stopped it. the stop command also silences RPC connection errors, so nothing is output if the node is already stopped when stop is run. - returns a response from stopNode before shutting down the node - removes error handling from 'client.connect' in stop command since the IronfishCommand abstract class handles these errors - adds output to 'stop' command indicating that it asks the node to shut down --- ironfish-cli/src/commands/stop.ts | 14 +++++++------- ironfish/src/rpc/routes/node/stopNode.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ironfish-cli/src/commands/stop.ts b/ironfish-cli/src/commands/stop.ts index 8a54410b90..e3ea4528d0 100644 --- a/ironfish-cli/src/commands/stop.ts +++ b/ironfish-cli/src/commands/stop.ts @@ -1,7 +1,8 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { IronfishNode, RpcConnectionError } from '@ironfish/sdk' +import { IronfishNode } from '@ironfish/sdk' +import { CliUx } from '@oclif/core' import { IronfishCommand } from '../command' import { RemoteFlags } from '../flags' @@ -17,13 +18,12 @@ export default class StopCommand extends IronfishCommand { async start(): Promise { await this.parse(StopCommand) - await this.sdk.client.connect().catch((e) => { - if (e instanceof RpcConnectionError) { - this.exit(0) - } - throw e - }) + await this.sdk.client.connect() + + CliUx.ux.action.start('Asking node to shut down...') await this.sdk.client.stopNode() + + CliUx.ux.action.stop('done.') } } diff --git a/ironfish/src/rpc/routes/node/stopNode.ts b/ironfish/src/rpc/routes/node/stopNode.ts index 4ce34c1db3..d0baf396fb 100644 --- a/ironfish/src/rpc/routes/node/stopNode.ts +++ b/ironfish/src/rpc/routes/node/stopNode.ts @@ -21,7 +21,7 @@ router.register( StopNodeRequestSchema, async (request, node): Promise => { node.logger.withTag('stopnode').info('Shutting down') - await node.shutdown() request.end() + await node.shutdown() }, )