Skip to content

Commit

Permalink
improves output of stop command (#3641)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hughy authored Mar 11, 2023
1 parent 4e905da commit 7090e73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions ironfish-cli/src/commands/stop.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -17,13 +18,12 @@ export default class StopCommand extends IronfishCommand {
async start(): Promise<void> {
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.')
}
}
2 changes: 1 addition & 1 deletion ironfish/src/rpc/routes/node/stopNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.register<typeof StopNodeRequestSchema, StopNodeResponse>(
StopNodeRequestSchema,
async (request, node): Promise<void> => {
node.logger.withTag('stopnode').info('Shutting down')
await node.shutdown()
request.end()
await node.shutdown()
},
)

0 comments on commit 7090e73

Please sign in to comment.