Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Handle piping error for commands that output to stdout #6098

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ rls*.log
.local
**/hfuzz_target/
**/hfuzz_workspace/
.cargo/
7 changes: 4 additions & 3 deletions client/cli/src/commands/build_spec_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use log::info;
use sc_network::config::build_multiaddr;
use sc_service::{config::MultiaddrWithPeerId, Configuration};
use structopt::StructOpt;
use std::io::Write;

/// The `build-spec` command used to build a specification.
#[derive(Debug, StructOpt, Clone)]
Expand Down Expand Up @@ -66,9 +67,9 @@ impl BuildSpecCmd {
}

let json = sc_service::chain_ops::build_spec(&*spec, raw_output)?;

print!("{}", json);

if let Err(_) = std::io::stdout().write_all(json.as_bytes()) {
bkchr marked this conversation as resolved.
Show resolved Hide resolved
let _ = std::io::stderr().write_all(b"Error writing to stdout\n");
}
Ok(())
}
}
Expand Down
8 changes: 4 additions & 4 deletions client/cli/src/commands/export_state_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
use log::info;
use sc_service::{Configuration, ServiceBuilderCommand};
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::{fmt::Debug, str::FromStr};
use std::{fmt::Debug, str::FromStr, io::Write};
use structopt::StructOpt;

/// The `export-state` command used to export the state of a given block into
Expand Down Expand Up @@ -65,9 +65,9 @@ impl ExportStateCmd {

info!("Generating new chain spec...");
let json = sc_service::chain_ops::build_spec(&*input_spec, true)?;

print!("{}", json);

if let Err(_) = std::io::stdout().write_all(json.as_bytes()) {
bkchr marked this conversation as resolved.
Show resolved Hide resolved
let _ = std::io::stderr().write_all(b"Error writing to stdout\n");
}
Ok(())
}
}
Expand Down