Skip to content

Commit af0b1e5

Browse files
Better error for missing install (#51)
Better elaboration for a common error where a foreman-managed tool is being used outside of a scope in which it's been defined as a tool dependency. Additionally, this tees up a 1.0.4 release.
1 parent 762a963 commit af0b1e5

File tree

7 files changed

+47
-14
lines changed

7 files changed

+47
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Foreman Changelog
22

3-
## Unreleased Changes
3+
## 1.0.4 (2022-05-13)
4+
5+
- Introduce improved error output on using uninstalled tools ([#51](https://github.com/Roblox/foreman/pull/51))
46
- Add support for Apple Silicon (arm64) binaries ([#46](https://github.com/Roblox/foreman/pull/46))
57

68
## 1.0.3 (2022-02-04)

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "foreman"
33
description = "Toolchain manager for simple binary tools"
4-
version = "1.0.3"
4+
version = "1.0.4"
55
authors = [
66
"Lucien Greathouse <[email protected]>",
77
"Matt Hargett <[email protected]>",

src/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ impl ConfigFile {
131131
}
132132
}
133133

134+
impl fmt::Display for ConfigFile {
135+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
136+
writeln!(f, "Available Tools:")?;
137+
for (name, spec) in self.tools.iter() {
138+
writeln!(f, "\t {} => {}", name, spec)?;
139+
}
140+
Ok(())
141+
}
142+
}
143+
134144
#[cfg(test)]
135145
mod test {
136146
use super::*;

src/error.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{fmt, io, path::PathBuf};
22

33
use semver::Version;
44

5-
use crate::config::ToolSpec;
5+
use crate::config::{ConfigFile, ToolSpec};
66

77
pub type ForemanResult<T> = Result<T, ForemanError>;
88

@@ -63,6 +63,11 @@ pub enum ForemanError {
6363
version: Version,
6464
message: String,
6565
},
66+
ToolNotInstalled {
67+
name: String,
68+
current_path: PathBuf,
69+
config_file: ConfigFile,
70+
},
6671
}
6772

6873
impl ForemanError {
@@ -283,6 +288,20 @@ impl fmt::Display for ForemanError {
283288
version,
284289
message
285290
),
291+
Self::ToolNotInstalled {
292+
name,
293+
current_path,
294+
config_file,
295+
} => write!(
296+
f,
297+
"'{}' is not a known Foreman tool, but Foreman was invoked \
298+
with its name.\n\nTo use this tool from {}, declare it in a \
299+
'foreman.toml' file in the current directory or a parent \
300+
directory.\n\n{}",
301+
name,
302+
current_path.display(),
303+
config_file,
304+
),
286305
}
287306
}
288307
}

src/main.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ impl ToolInvocation {
7272

7373
Ok(())
7474
} else {
75-
eprintln!(
76-
"'{}' is not a known Foreman tool, but Foreman was invoked with its name.",
77-
self.name
78-
);
79-
eprintln!("You may not have this tool installed here, or your install may be broken.");
80-
81-
Ok(())
75+
let current_dir = env::current_dir().map_err(|err| {
76+
ForemanError::io_error_with_context(
77+
err,
78+
"unable to obtain the current working directory",
79+
)
80+
})?;
81+
Err(ForemanError::ToolNotInstalled {
82+
name: self.name,
83+
current_path: current_dir,
84+
config_file: config,
85+
})
8286
}
8387
}
8488
}

tests/snapshots/help_command.snap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
22
source: tests/cli.rs
3-
assertion_line: 93
43
expression: content
5-
64
---
7-
foreman 1.0.3
5+
foreman 1.0.4
86

97
USAGE:
108
foreman [FLAGS] <SUBCOMMAND>

0 commit comments

Comments
 (0)