From f235daf1c760d7d0e39b46c9d97c73a496af4bc0 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 17 May 2024 16:31:17 -0400 Subject: [PATCH 1/2] Write all diagnostic messages to standard error. Signed-off-by: Gene Johnston --- zowex/Cargo.lock | 2 +- zowex/Cargo.toml | 2 +- zowex/src/comm.rs | 18 ++++++++-------- zowex/src/proc.rs | 14 ++++++------ zowex/src/run.rs | 54 +++++++++++++++++++++++------------------------ zowex/src/util.rs | 14 ++++++------ 6 files changed, 52 insertions(+), 52 deletions(-) diff --git a/zowex/Cargo.lock b/zowex/Cargo.lock index c456ddf987..301095f6e6 100644 --- a/zowex/Cargo.lock +++ b/zowex/Cargo.lock @@ -830,7 +830,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zowe" -version = "1.2.2" +version = "1.2.3" dependencies = [ "base64", "fslock", diff --git a/zowex/Cargo.toml b/zowex/Cargo.toml index 4e04d82592..973093361e 100644 --- a/zowex/Cargo.toml +++ b/zowex/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zowe" -version = "1.2.2" +version = "1.2.3" authors = ["Zowe Project"] edition = "2018" license = "EPL-2.0" diff --git a/zowex/src/comm.rs b/zowex/src/comm.rs index f147f1337d..415cfc9458 100644 --- a/zowex/src/comm.rs +++ b/zowex/src/comm.rs @@ -9,7 +9,7 @@ * */ -// Functions related to daemon cummunication. +// Functions related to daemon communication. use std::io; use std::io::prelude::*; @@ -96,11 +96,11 @@ pub async fn comm_establish_connection( we_started_daemon = true; cmd_to_show = proc_start_daemon(njs_zowe_path); } else if we_started_daemon && conn_retries > THREE_MIN_OF_RETRIES { - println!( + eprintln!( "The Zowe daemon that we started is not running on socket: {}.", daemon_socket ); - println!( + eprintln!( "Command used to start the Zowe daemon was:\n {}\nTerminating.", cmd_to_show ); @@ -115,7 +115,7 @@ pub async fn comm_establish_connection( }; if conn_retries > 0 { - println!( + eprintln!( "{} ({} of {})", retry_msg, conn_retries, THREE_MIN_OF_RETRIES ); @@ -124,7 +124,7 @@ pub async fn comm_establish_connection( conn_retries += 1; if conn_retries > THREE_MIN_OF_RETRIES { - println!( + eprintln!( "Terminating after {} connection retries.", THREE_MIN_OF_RETRIES ); @@ -136,13 +136,13 @@ pub async fn comm_establish_connection( // before we wait too long, show diagnostics if conn_retries == RETRY_TO_SHOW_DIAG { - println!("\nThe Zowe daemon was started with these options:"); + eprintln!("\nThe Zowe daemon was started with these options:"); if we_started_daemon { - println!("Command = {}", cmd_to_show); + eprintln!("Command = {}", cmd_to_show); } else { - println!("Command = {}", daemon_proc_info.cmd); + eprintln!("Command = {}", daemon_proc_info.cmd); } - println!( + eprintln!( "Process name = {} pid = {} socket = {}\n", daemon_proc_info.name, daemon_proc_info.pid, daemon_socket ); diff --git a/zowex/src/proc.rs b/zowex/src/proc.rs index 5cbd0bcdb1..51eb19f5b0 100644 --- a/zowex/src/proc.rs +++ b/zowex/src/proc.rs @@ -196,7 +196,7 @@ fn read_pid_for_user() -> Option { Ok(ok_val) => ok_val, Err(err_val) => { // we should not continue if we cannot open an existing pid file - println!( + eprintln!( "Unable to open file = {}\nDetails = {}", pid_file_path.display(), err_val @@ -209,7 +209,7 @@ fn read_pid_for_user() -> Option { Ok(ok_val) => ok_val, Err(err_val) => { // we should not continue if we cannot read an existing pid file - println!( + eprintln!( "Unable to read file = {}\nDetails = {}", pid_file_path.display(), err_val @@ -222,7 +222,7 @@ fn read_pid_for_user() -> Option { if daemon_pid_for_user.user != executor { // our pid file should only contain our own user name - println!( + eprintln!( "User name of '{}' in file '{}' does not match current user = '{}'.", daemon_pid_for_user.user, pid_file_path.display(), @@ -273,11 +273,11 @@ fn read_pid_for_user() -> Option { */ pub fn proc_start_daemon(njs_zowe_path: &str) -> String { - println!("Starting a background process to increase performance ..."); + eprintln!("Starting a background process to increase performance ..."); let daemon_arg = LAUNCH_DAEMON_OPTION; let mut cmd = Command::new(njs_zowe_path); - + // Uses creation flags from https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags // Flags are CREATE_NO_WINDOW, CREATE_NEW_PROCESS_GROUP, and CREATE_UNICODE_ENVIRONMENT #[cfg(target_family = "windows")] @@ -291,11 +291,11 @@ pub fn proc_start_daemon(njs_zowe_path: &str) -> String { { Ok(_unused) => { /* nothing to do */ } Err(error) => { - println!( + eprintln!( "Failed to start the following process:\n {} {}", njs_zowe_path, daemon_arg ); - println!("Due to this error:\n {}", error); + eprintln!("Due to this error:\n {}", error); std::process::exit(EXIT_CODE_CANNOT_START_DAEMON); } }; diff --git a/zowex/src/run.rs b/zowex/src/run.rs index b01ba1a6b7..2d5ff8f077 100644 --- a/zowex/src/run.rs +++ b/zowex/src/run.rs @@ -96,17 +96,17 @@ pub async fn run_zowe_command(zowe_cmd_args: &mut Vec) -> Result Result { if proc_get_daemon_info().is_running { - println!("Shutting down the running daemon ..."); + eprintln!("Shutting down the running daemon ..."); let mut restart_cmd_args: Vec = vec![SHUTDOWN_REQUEST.to_string()]; if let Err(err_val) = run_daemon_command(njs_zowe_path, &mut restart_cmd_args).await { - println!("Unable to communicate a command to the Zowe daemon."); + eprintln!("Unable to communicate a command to the Zowe daemon."); return Err(err_val); } } // Start a new daemon. Note that proc_start_daemon() exits on failure. proc_start_daemon(njs_zowe_path); - println!("A new daemon has started."); + eprintln!("A new daemon has started."); Ok(EXIT_CODE_SUCCESS) } @@ -134,12 +134,12 @@ fn run_nodejs_command(njs_zowe_path: &str, zowe_cmd_args: &mut Vec) -> R { Ok(new_proc) => new_proc.status.code().unwrap(), Err(error) => { - println!("Failed to run the following command:"); - println!( + eprintln!("Failed to run the following command:"); + eprintln!( " Program = {}\n arguments = {:?}", njs_zowe_path, zowe_cmd_args ); - println!("Due to this error:\n {}", error); + eprintln!("Due to this error:\n {}", error); EXIT_CODE_FAILED_TO_RUN_NODEJS_CMD } }; @@ -177,12 +177,12 @@ fn run_delayed_zowe_command(njs_zowe_path: &str, zowe_cmd_args: &[String]) -> Re let (curr_cmd_shell, cmd_shell_nm) = match proc_get_cmd_shell() { Ok((curr_cmd_shell, cmd_shell_nm)) => (curr_cmd_shell, cmd_shell_nm), Err(error) => { - println!("{} Terminating.", error); + eprintln!("{} Terminating.", error); return Err(EXIT_CODE_CANT_FIND_CMD_SHELL); } }; if matches!(curr_cmd_shell, CmdShell::Unknown) { - println!( + eprintln!( "The command shell process named '{}' is unknown to the Zowe CLI. Terminating.", cmd_shell_nm ); @@ -205,9 +205,9 @@ fn run_delayed_zowe_command(njs_zowe_path: &str, zowe_cmd_args: &[String]) -> Re ); // The following line gives useful debugging info when it is uncommented. - // println!("script_arg_vec = {:?}", script_arg_vec); + // eprintln!("script_arg_vec = {:?}", script_arg_vec); - println!( + eprintln!( "The '{}' command will run in the background ...", arg_vec_to_string(zowe_cmd_args) ); @@ -220,12 +220,12 @@ fn run_delayed_zowe_command(njs_zowe_path: &str, zowe_cmd_args: &[String]) -> Re { Ok(..) => Ok(EXIT_CODE_SUCCESS), Err(err_val) => { - println!("Failed to run the following command:"); - println!( + eprintln!("Failed to run the following command:"); + eprintln!( " cmd_shell_to_launch = {}\n arguments = {:?}", njs_zowe_path, zowe_cmd_args ); - println!("Due to this error:\n {}", err_val); + eprintln!("Due to this error:\n {}", err_val); Err(EXIT_CODE_FAILED_TO_RUN_NODEJS_CMD) } }; @@ -252,7 +252,7 @@ pub async fn run_daemon_command( let cwd: PathBuf = match env::current_dir() { Ok(ok_val) => ok_val, Err(err_val) => { - println!("Unable to get current directory\nDetails = {:?}", err_val); + eprintln!("Unable to get current directory\nDetails = {:?}", err_val); return Err(EXIT_CODE_ENV_ERROR); } }; @@ -260,7 +260,7 @@ pub async fn run_daemon_command( let mut stdin = Vec::new(); if !std::io::stdin().is_terminal() { if let Err(err_val) = io::stdin().read_to_end(&mut stdin) { - println!("Failed reading stdin\nDetails = {}", err_val); + eprintln!("Failed reading stdin\nDetails = {}", err_val); return Err(EXIT_CODE_COMM_IO_ERROR); } } @@ -301,7 +301,7 @@ pub async fn run_daemon_command( } } Err(err_val) => { - println!("Failed convert response to JSON\nDetails = {}", err_val); + eprintln!("Failed to convert response to JSON\nDetails = {}", err_val); return Err(EXIT_CODE_CANT_CONVERT_JSON); } } @@ -323,7 +323,7 @@ pub async fn run_daemon_command( match lock_file.try_lock() { Ok(result) if !result => { if tries > THREE_MIN_OF_RETRIES { - println!( + eprintln!( "Terminating after {} connection retries.", THREE_MIN_OF_RETRIES ); @@ -331,7 +331,7 @@ pub async fn run_daemon_command( } tries += 1; - println!( + eprintln!( "The Zowe daemon is in use, retrying ({} of {})", tries, THREE_MIN_OF_RETRIES ); @@ -344,7 +344,7 @@ pub async fn run_daemon_command( locked = true; } Err(ref e) => { - println!("Problem acquiring lock: {:?}", e); + eprintln!("Problem acquiring lock: {:?}", e); return Err(EXIT_CODE_CANNOT_ACQUIRE_LOCK); } } @@ -354,7 +354,7 @@ pub async fn run_daemon_command( match comm_establish_connection(njs_zowe_path, &socket_string).await { Ok(ok_val) => stream = ok_val, Err(err_val) => { - println!( + eprintln!( "Unable to establish communication with daemon.\nDetails = {}", err_val ); @@ -369,7 +369,7 @@ pub async fn run_daemon_command( Err(ref err_val) => { if err_val.kind() == io::ErrorKind::ConnectionReset { if tries > THREE_MIN_OF_RETRIES { - println!( + eprintln!( "Terminating after {} connection retries.", THREE_MIN_OF_RETRIES ); @@ -377,7 +377,7 @@ pub async fn run_daemon_command( } tries += 1; - println!( + eprintln!( "The Zowe daemon is in use, retrying ({} of {})", tries, THREE_MIN_OF_RETRIES ); @@ -385,7 +385,7 @@ pub async fn run_daemon_command( // pause between attempts to connect thread::sleep(Duration::from_secs(THREE_SEC_DELAY)); } else { - println!( + eprintln!( "I/O error during daemon communication.\nDetails = {}", err_val ); @@ -648,21 +648,21 @@ fn get_win_lock_file() -> Result { lock_path.push("daemon.lock"); if let Err(err_val) = File::create(&lock_path) { - println!( + eprintln!( "Unable to create zowe daemon lock file = {}.", &lock_path.display() ); - println!("Reason = {}.", err_val); + eprintln!("Reason = {}.", err_val); return Err(EXIT_CODE_FILE_IO_ERROR); } let lock_file: LockFile = match LockFile::open(&lock_path) { Ok(ok_val) => ok_val, Err(err_val) => { - println!( + eprintln!( "Unable to open zowe daemon lock file = {}.", &lock_path.display() ); - println!("Reason = {}.", err_val); + eprintln!("Reason = {}.", err_val); return Err(EXIT_CODE_FILE_IO_ERROR); } }; diff --git a/zowex/src/util.rs b/zowex/src/util.rs index fb607309d9..53cbe1ef31 100644 --- a/zowex/src/util.rs +++ b/zowex/src/util.rs @@ -44,7 +44,7 @@ pub fn util_get_nodejs_zowe_path() -> String { */ let my_exe_result = env::current_exe(); if my_exe_result.is_err() { - println!("Unable to get path to my own executable. Terminating."); + eprintln!("Unable to get path to my own executable. Terminating."); std::process::exit(EXIT_CODE_CANNOT_GET_MY_PATH); } let my_exe_path_buf = my_exe_result.unwrap(); @@ -73,8 +73,8 @@ pub fn util_get_nodejs_zowe_path() -> String { break; } if njs_zowe_path == NOT_FOUND { - println!("Could not find a NodeJS zowe command on your path."); - println!("Will not be able to run Zowe commands. Terminating."); + eprintln!("Could not find a NodeJS zowe command on your path."); + eprintln!("Will not be able to run Zowe commands. Terminating."); std::process::exit(EXIT_CODE_NO_NODEJS_ZOWE_ON_PATH); } @@ -96,7 +96,7 @@ pub fn util_get_daemon_dir() -> Result { match home_dir() { Some(path_buf_val) => daemon_dir = path_buf_val, None => { - println!("Unable to get user's home directory."); + eprintln!("Unable to get user's home directory."); return Err(EXIT_CODE_ENV_ERROR); } } @@ -106,11 +106,11 @@ pub fn util_get_daemon_dir() -> Result { if !daemon_dir.exists() { if let Err(err_val) = std::fs::create_dir_all(&daemon_dir) { - println!( + eprintln!( "Unable to create zowe daemon directory = {}.", &daemon_dir.display() ); - println!("Reason = {}.", err_val); + eprintln!("Reason = {}.", err_val); return Err(EXIT_CODE_FILE_IO_ERROR); } } @@ -178,6 +178,6 @@ pub fn util_terminal_supports_color() -> i32 { return 1; } } - + 0 } \ No newline at end of file From 80fe5118af1a0a0d0c113f38a328e78b0f8966fd Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 22 May 2024 15:26:41 -0400 Subject: [PATCH 2/2] Add CHANGELOG entry Signed-off-by: Gene Johnston --- packages/cli/CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index fb905086c3..f9205c3d5c 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -2,13 +2,17 @@ All notable changes to the Zowe CLI package will be documented in this file. +## Recent Changes + +- LTS Breaking: Send all Zowe Daemon informational messages, progress messages, and error messages to standard error instead of standard output [#1451](https://github.com/zowe/zowe-cli/issues/1451) + ## `8.0.0-next.202405202020` - BugFix: Fixed a bug where a data set search would not return a search term if it was at the beginning of a line. [#2147](https://github.com/zowe/zowe-cli/pull/2147) ## `8.0.0-next.202405101931` -- Enhancement: Added the ability to search for a string in a data set or PDS member matching a pattern with the `zowe zos-files search data-sets` comamnd.[#2095](https://github.com/zowe/zowe-cli/issues/2095) +- Enhancement: Added the ability to search for a string in a data set or PDS member matching a pattern with the `zowe zos-files search data-sets` command.[#2095](https://github.com/zowe/zowe-cli/issues/2095) ## `8.0.0-next.202405061946`