diff options
author | Alexandru Macovei <alexnmaco@gmail.com> | 2022-11-05 17:51:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-05 16:51:03 +0100 |
commit | e371153034db126235f342b52e2e6301e0880e70 (patch) | |
tree | 96d1fbebe97e772bddb0933f952d4578bc000f72 /src/clipboard.rs | |
parent | a172b184284f448819f74fa968ef3677c8d297d0 (diff) |
Report failure to copy to clipboard (#1410)
* (refactor) move copy_commit_hash from revlog into commitlist, and make fewer functions public in commitlist
* (refactor) reduce duplication in commit copying code; use already-stored commits instead of looking up items
* (clipboard) actually check subprocess exit status, and report failure instead of ignoring it
* (commitlist) display popup with copy failure instead of exiting the application on error
Diffstat (limited to 'src/clipboard.rs')
-rw-r--r-- | src/clipboard.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/clipboard.rs b/src/clipboard.rs index fcb6af12..61170fe2 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -17,6 +17,7 @@ fn exec_copy_with_args( .args(args) .stdin(Stdio::piped()) .stdout(Stdio::null()) + .stderr(Stdio::piped()) .spawn() .map_err(|e| anyhow!("`{:?}`: {}", command, e))?; @@ -27,11 +28,20 @@ fn exec_copy_with_args( .write_all(text.as_bytes()) .map_err(|e| anyhow!("`{:?}`: {}", command, e))?; - process - .wait() + let out = process + .wait_with_output() .map_err(|e| anyhow!("`{:?}`: {}", command, e))?; - Ok(()) + if out.status.success() { + Ok(()) + } else { + let msg = if out.stderr.is_empty() { + format!("{}", out.status).into() + } else { + String::from_utf8_lossy(&out.stderr) + }; + Err(anyhow!("`{command:?}`: {msg}")) + } } fn exec_copy(command: &str, text: &str) -> Result<()> { |