2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
2021-07-26 01:26:06 -07:00
|
|
|
pub(crate) struct CompileError<'src> {
|
2019-11-13 19:32:50 -08:00
|
|
|
pub(crate) token: Token<'src>,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) kind: CompileErrorKind<'src>,
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
impl<'src> CompileError<'src> {
|
|
|
|
pub(crate) fn context(&self) -> Token<'src> {
|
|
|
|
self.token
|
|
|
|
}
|
|
|
|
}
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
impl Display for CompileError<'_> {
|
2019-04-11 15:23:14 -07:00
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
2021-07-26 01:26:06 -07:00
|
|
|
use CompileErrorKind::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2021-03-28 22:38:07 -07:00
|
|
|
match &self.kind {
|
2019-04-11 12:30:29 -07:00
|
|
|
AliasShadowsRecipe { alias, recipe_line } => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2019-04-11 12:30:29 -07:00
|
|
|
f,
|
2019-10-19 20:00:41 -07:00
|
|
|
"Alias `{}` defined on line {} shadows recipe `{}` defined on line {}",
|
2019-04-11 12:30:29 -07:00
|
|
|
alias,
|
2019-11-13 19:32:50 -08:00
|
|
|
self.token.line.ordinal(),
|
2019-10-19 20:00:41 -07:00
|
|
|
alias,
|
2019-04-19 02:17:43 -07:00
|
|
|
recipe_line.ordinal(),
|
2019-04-11 12:30:29 -07:00
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-04-05 21:28:37 -07:00
|
|
|
BacktickShebang => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(f, "Backticks may not start with `#!`")?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
|
|
|
CircularRecipeDependency { recipe, ref circle } => {
|
2017-11-16 23:30:08 -08:00
|
|
|
if circle.len() == 2 {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(f, "Recipe `{}` depends on itself", recipe)?;
|
2017-11-16 23:30:08 -08:00
|
|
|
} else {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2018-12-08 14:29:41 -08:00
|
|
|
f,
|
|
|
|
"Recipe `{}` has circular dependency `{}`",
|
|
|
|
recipe,
|
|
|
|
circle.join(" -> ")
|
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 14:29:41 -08:00
|
|
|
CircularVariableDependency {
|
|
|
|
variable,
|
|
|
|
ref circle,
|
2021-09-16 06:44:40 -07:00
|
|
|
} => {
|
2017-11-16 23:30:08 -08:00
|
|
|
if circle.len() == 2 {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(f, "Variable `{}` is defined in terms of itself", variable)?;
|
2017-11-16 23:30:08 -08:00
|
|
|
} else {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2018-12-08 14:29:41 -08:00
|
|
|
f,
|
|
|
|
"Variable `{}` depends on its own value: `{}`",
|
|
|
|
variable,
|
|
|
|
circle.join(" -> ")
|
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
DependencyArgumentCountMismatch {
|
|
|
|
dependency,
|
|
|
|
found,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
} => {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"Dependency `{}` got {} {} but takes ",
|
|
|
|
dependency,
|
|
|
|
found,
|
|
|
|
Count("argument", *found),
|
|
|
|
)?;
|
2018-06-30 19:19:13 -07:00
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
if min == max {
|
|
|
|
let expected = min;
|
|
|
|
write!(f, "{} {}", expected, Count("argument", *expected))?;
|
|
|
|
} else if found < min {
|
|
|
|
write!(f, "at least {} {}", min, Count("argument", *min))?;
|
|
|
|
} else {
|
|
|
|
write!(f, "at most {} {}", max, Count("argument", *max))?;
|
|
|
|
}
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2019-04-11 12:30:29 -07:00
|
|
|
DuplicateAlias { alias, first } => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2019-04-11 12:30:29 -07:00
|
|
|
f,
|
2019-10-19 20:00:41 -07:00
|
|
|
"Alias `{}` first defined on line {} is redefined on line {}",
|
2019-04-11 12:30:29 -07:00
|
|
|
alias,
|
2019-04-19 02:17:43 -07:00
|
|
|
first.ordinal(),
|
2019-11-13 19:32:50 -08:00
|
|
|
self.token.line.ordinal(),
|
2019-04-11 12:30:29 -07:00
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
DuplicateParameter { recipe, parameter } => {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"Recipe `{}` has duplicate parameter `{}`",
|
|
|
|
recipe, parameter
|
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2018-12-08 14:29:41 -08:00
|
|
|
DuplicateRecipe { recipe, first } => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2018-12-08 14:29:41 -08:00
|
|
|
f,
|
|
|
|
"Recipe `{}` first defined on line {} is redefined on line {}",
|
|
|
|
recipe,
|
2019-04-19 02:17:43 -07:00
|
|
|
first.ordinal(),
|
2019-11-13 19:32:50 -08:00
|
|
|
self.token.line.ordinal()
|
2018-12-08 14:29:41 -08:00
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2019-11-10 23:17:47 -08:00
|
|
|
DuplicateSet { setting, first } => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2019-11-10 23:17:47 -08:00
|
|
|
f,
|
|
|
|
"Setting `{}` first set on line {} is redefined on line {}",
|
|
|
|
setting,
|
|
|
|
first.ordinal(),
|
2019-11-13 19:32:50 -08:00
|
|
|
self.token.line.ordinal(),
|
2019-11-10 23:17:47 -08:00
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
DuplicateVariable { variable } => {
|
|
|
|
write!(f, "Variable `{}` has multiple definitions", variable)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
ExpectedKeyword { expected, found } => write!(
|
2020-10-26 18:16:42 -07:00
|
|
|
f,
|
2021-03-28 22:38:07 -07:00
|
|
|
"Expected keyword {} but found identifier `{}`",
|
|
|
|
List::or_ticked(expected),
|
|
|
|
found
|
2020-10-26 18:16:42 -07:00
|
|
|
)?,
|
2017-11-16 23:30:08 -08:00
|
|
|
ExtraLeadingWhitespace => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(f, "Recipe line has extra leading whitespace")?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2018-12-08 14:29:41 -08:00
|
|
|
FunctionArgumentCountMismatch {
|
|
|
|
function,
|
|
|
|
found,
|
|
|
|
expected,
|
|
|
|
} => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2017-12-02 14:59:07 -08:00
|
|
|
f,
|
2019-10-09 01:40:40 -07:00
|
|
|
"Function `{}` called with {} {} but takes {}",
|
2018-12-08 14:29:41 -08:00
|
|
|
function,
|
|
|
|
found,
|
2021-03-28 22:38:07 -07:00
|
|
|
Count("argument", *found),
|
2021-10-14 17:00:58 -07:00
|
|
|
expected.display(),
|
2017-12-02 14:59:07 -08:00
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2018-12-08 14:29:41 -08:00
|
|
|
InconsistentLeadingWhitespace { expected, found } => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2018-12-08 14:29:41 -08:00
|
|
|
f,
|
2020-02-10 20:07:06 -08:00
|
|
|
"Recipe line has inconsistent leading whitespace. Recipe started with `{}` but found \
|
|
|
|
line with `{}`",
|
2019-10-09 01:40:40 -07:00
|
|
|
ShowWhitespace(expected),
|
|
|
|
ShowWhitespace(found)
|
2017-11-16 23:30:08 -08:00
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
Internal { ref message } => {
|
|
|
|
write!(
|
2018-12-08 14:29:41 -08:00
|
|
|
f,
|
2021-07-26 01:26:06 -07:00
|
|
|
"Internal error, this may indicate a bug in just: {}\n\
|
|
|
|
consider filing an issue: https://github.com/casey/just/issues/new",
|
|
|
|
message
|
2018-12-08 14:29:41 -08:00
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
InvalidEscapeSequence { character } => {
|
|
|
|
let representation = match character {
|
|
|
|
'`' => r"\`".to_owned(),
|
|
|
|
'\\' => r"\".to_owned(),
|
|
|
|
'\'' => r"'".to_owned(),
|
|
|
|
'"' => r#"""#.to_owned(),
|
|
|
|
_ => character.escape_default().collect(),
|
|
|
|
};
|
|
|
|
write!(f, "`\\{}` is not a valid escape sequence", representation)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2020-10-27 23:51:17 -07:00
|
|
|
MismatchedClosingDelimiter {
|
|
|
|
open,
|
|
|
|
open_line,
|
|
|
|
close,
|
|
|
|
} => {
|
2021-07-26 01:26:06 -07:00
|
|
|
write!(
|
2020-10-27 23:51:17 -07:00
|
|
|
f,
|
|
|
|
"Mismatched closing delimiter `{}`. (Did you mean to close the `{}` on line {}?)",
|
|
|
|
close.close(),
|
|
|
|
open.open(),
|
|
|
|
open_line.ordinal(),
|
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
MixedLeadingWhitespace { whitespace } => {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"Found a mix of tabs and spaces in leading whitespace: `{}`\nLeading whitespace may \
|
|
|
|
consist of tabs or spaces, but not both",
|
|
|
|
ShowWhitespace(whitespace)
|
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
ParameterFollowsVariadicParameter { parameter } => {
|
|
|
|
write!(f, "Parameter `{}` follows variadic parameter", parameter)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
ParameterShadowsVariable { parameter } => {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"Parameter `{}` shadows variable of the same name",
|
|
|
|
parameter
|
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
RequiredParameterFollowsDefaultParameter { parameter } => {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"Non-default parameter `{}` follows default parameter",
|
|
|
|
parameter
|
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UndefinedVariable { variable } => {
|
|
|
|
write!(f, "Variable `{}` not defined", variable)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnexpectedCharacter { expected } => {
|
|
|
|
write!(f, "Expected character `{}`", expected)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnexpectedClosingDelimiter { close } => {
|
|
|
|
write!(f, "Unexpected closing delimiter `{}`", close.close())?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnexpectedEndOfToken { expected } => {
|
|
|
|
write!(f, "Expected character `{}` but found end-of-file", expected)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnexpectedToken {
|
|
|
|
ref expected,
|
|
|
|
found,
|
|
|
|
} => {
|
|
|
|
write!(f, "Expected {}, but found {}", List::or(expected), found)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnknownAliasTarget { alias, target } => {
|
|
|
|
write!(f, "Alias `{}` has an unknown target `{}`", alias, target)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnknownDependency { recipe, unknown } => {
|
|
|
|
write!(
|
2018-12-08 14:29:41 -08:00
|
|
|
f,
|
2021-07-26 01:26:06 -07:00
|
|
|
"Recipe `{}` has unknown dependency `{}`",
|
|
|
|
recipe, unknown
|
2018-12-08 14:29:41 -08:00
|
|
|
)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnknownFunction { function } => {
|
|
|
|
write!(f, "Call to unknown function `{}`", function)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnknownSetting { setting } => {
|
|
|
|
write!(f, "Unknown setting `{}`", setting)?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnknownStartOfToken => {
|
|
|
|
write!(f, "Unknown start of token:")?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnpairedCarriageReturn => {
|
|
|
|
write!(f, "Unpaired carriage return")?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnterminatedBacktick => {
|
|
|
|
write!(f, "Unterminated backtick")?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnterminatedInterpolation => {
|
|
|
|
write!(f, "Unterminated interpolation")?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2021-07-26 01:26:06 -07:00
|
|
|
UnterminatedString => {
|
|
|
|
write!(f, "Unterminated string")?;
|
2021-09-16 06:44:40 -07:00
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
Ok(())
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|