Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest a tool is missing when spawning returns ENOTFOUND #221

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
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
12 changes: 9 additions & 3 deletions src/tools.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use itertools::Itertools;
use std::{
io::{self, Write},
process::{Command, Output, Stdio},
};

use itertools::Itertools;

const MAX_ERROR_LINES: usize = 10;

pub(crate) struct ThirdPartyTools;
Expand Down Expand Up @@ -63,7 +62,11 @@ impl Tool {
if self.stdin.is_some() {
self.command.stdin(Stdio::piped());
}
let mut child = self.command.spawn().map_err(|error| Spawn { command: self.command_name, error })?;
let mut child = match self.command.spawn() {
Ok(child) => child,
Err(e) if e.kind() == io::ErrorKind::NotFound => return Err(SpawnNotFound { command: self.command_name }),
Err(error) => return Err(Spawn { command: self.command_name, error }),
};
if let Some(data) = &self.stdin {
let mut stdin = child.stdin.take().expect("no stdin");
stdin
Expand Down Expand Up @@ -91,6 +94,9 @@ pub enum ExecutionError {
#[error("spawning '{command}' failed: {error}")]
Spawn { command: &'static str, error: io::Error },

#[error("spawning '{command}' failed (is '{command}' installed?)")]
SpawnNotFound { command: &'static str },

#[error("communicating with '{command}' failed: {error}")]
Communication { command: &'static str, error: io::Error },

Expand Down
Loading