Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.82.0
toolchain: 1.85.0

- uses: Swatinem/rust-cache@v2

Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ keywords = ["command-line", "task", "runner", "development", "utility"]
license = "CC0-1.0"
readme = "crates-io-readme.md"
repository = "https://github.com/casey/just"
rust-version = "1.82.0"
rust-version = "1.85.0"

[workspace]
members = [".", "crates/*"]

[dependencies]
ansi_term = "0.12.0"
ariadne = "0.6.0"
blake3 = { version = "1.5.0", features = ["rayon", "mmap"] }
camino = "1.0.4"
chrono = "0.4.38"
Expand Down
59 changes: 59 additions & 0 deletions src/compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,65 @@ impl<'src> CompileError<'src> {
}
}

pub(crate) fn render_compile_error(error: &CompileError, color: Color) {
use ariadne::{Config, Label, Report, ReportKind, Source};

let source = Source::from(error.token.src);

let start = error.token.offset;
let end = start + error.token.length;
let path = error.token.path.display().to_string();
let label = Label::new((&path, start..end));

let config = Config::default().with_color(color.stderr().active());
let report = Report::build(ReportKind::Error, (&path, start..end)).with_config(config);

let report = match &*error.kind {
CompileErrorKind::AttributeArgumentCountMismatch {
attribute,
found,
min,
max,
} => {
let label_msg = format!("Found {found} {}", Count("argument", *found));

let note = if min == max {
format!("`{attribute}` takes {min} {}", Count("argument", *min))
} else if *max == usize::MAX {
format!(
"`{attribute}` takes at least {min} {}",
Count("argument", *min)
)
} else {
format!("`{attribute}` takes between {min} and {max} arguments")
};

report
.with_message("Attribute argument count mismatch")
.with_label(label.with_message(label_msg))
.with_note(note)
.finish()
}
CompileErrorKind::DuplicateAttribute { attribute, first } => {
let original_label = source
.line(*first)
.map(|line| Label::new((&path, line.span())).with_message("original"));

let mut report = report.with_message(format!("Duplicate attribute `{attribute}`"));
if let Some(original) = original_label {
report = report.with_label(original);
}
report.with_label(label.with_message("duplicate")).finish()
}
_ => {
let message = format!("{error}");
report.with_message(message).with_label(label).finish()
}
};

report.eprint((&path, source)).unwrap();
}

fn capitalize(s: &str) -> String {
let mut chars = s.chars();
match chars.next() {
Expand Down
7 changes: 7 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,13 @@ impl ColorDisplay for Error<'_> {
}
}

pub(crate) fn render_error(error: &Error, color: Color) {
match error {
Error::Compile { compile_error } => compile_error::render_compile_error(compile_error, color),
_ => eprintln!("{}", error.color_display(color.stderr())),
}
}

fn format_cmd(binary: &OsString, arguments: &Vec<OsString>) -> String {
iter::once(binary)
.chain(arguments)
Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn run(args: impl Iterator<Item = impl Into<OsString> + Clone>) -> Result<()
})
.map_err(|error| {
if !verbosity.quiet() && error.print_message() {
eprintln!("{}", error.color_display(color.stderr()));
crate::error::render_error(&error, color);
}
error.code().unwrap_or(EXIT_FAILURE)
})
Expand Down
11 changes: 5 additions & 6 deletions tests/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ fn unknown_nested_alias() {
)
.arg("b")
.stderr(
"\
error: Alias `b` has an unknown target `foo::bar::baz`
——▶ justfile:3:7
3 │ alias b := foo::bar::baz
│ ^
r"Error: Alias `b` has an unknown target `foo::bar::baz`
╭─[ justfile:3:7 ]
3 │ alias b := foo::bar::baz
───╯
",
)
.failure();
Expand Down
13 changes: 6 additions & 7 deletions tests/allow_missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ fn allow_missing_does_not_apply_to_compilation_errors() {
.justfile("bar: foo")
.args(["--allow-missing", "foo"])
.stderr(
"
error: Recipe `bar` has unknown dependency `foo`
——▶ justfile:1:6
1 │ bar: foo
│ ^^^
",
r"Error: Recipe `bar` has unknown dependency `foo`
╭─[ justfile:1:6 ]
1 │ bar: foo
───╯
",
)
.failure();
}
Expand Down
108 changes: 48 additions & 60 deletions tests/arg_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,12 @@ fn pattern_invalid_regex_error() {
",
)
.stderr(
"
error: Failed to parse argument pattern
——▶ justfile:1:21
1 │ [arg('bar', pattern='{')]
│ ^^^
caused by: regex parse error:
{
^
error: repetition operator missing expression
",
r"Error: Failed to parse argument pattern
╭─[ justfile:1:21 ]
1 │ [arg('bar', pattern='{')]
───╯
",
)
.failure();
}
Expand Down Expand Up @@ -123,13 +118,12 @@ fn duplicate_attribute_error() {
)
.args(["foo", "BAR"])
.stderr(
"
error: Recipe attribute for argument `bar` first used on line 1 is duplicated on line 2
——▶ justfile:2:2
2 │ [arg('bar', pattern='BAR')]
│ ^^^
",
r"Error: Recipe attribute for argument `bar` first used on line 1 is duplicated on line 2
╭─[ justfile:2:2 ]
2 │ [arg('bar', pattern='BAR')]
───╯
",
)
.failure();
}
Expand All @@ -145,13 +139,12 @@ fn extra_keyword_error() {
)
.args(["foo", "BAR"])
.stderr(
"
error: Unknown keyword `foo` for `arg` attribute
——▶ justfile:1:28
1 │ [arg('bar', pattern='BAR', foo='foo')]
│ ^^^
",
r"Error: Unknown keyword `foo` for `arg` attribute
╭─[ justfile:1:28 ]
1 │ [arg('bar', pattern='BAR', foo='foo')]
───╯
",
)
.failure();
}
Expand All @@ -167,13 +160,12 @@ fn unknown_argument_error() {
)
.arg("foo")
.stderr(
"
error: Argument attribute for undefined argument `bar`
——▶ justfile:1:6
1 │ [arg('bar', pattern='BAR')]
│ ^^^^^
",
r"Error: Argument attribute for undefined argument `bar`
╭─[ justfile:1:6 ]
1 │ [arg('bar', pattern='BAR')]
───╯
",
)
.failure();
}
Expand Down Expand Up @@ -221,13 +213,12 @@ fn positional_arguments_cannot_follow_keyword_arguments() {
)
.args(["foo", "BAR"])
.stderr(
"
error: Positional attribute arguments cannot follow keyword attribute arguments
——▶ justfile:1:21
1 │ [arg(pattern='BAR', 'bar')]
│ ^^^^^
",
r"Error: Positional attribute arguments cannot follow keyword attribute arguments
╭─[ justfile:1:21 ]
1 │ [arg(pattern='BAR', 'bar')]
───╯
",
)
.failure();
}
Expand Down Expand Up @@ -352,13 +343,12 @@ fn pattern_requires_value() {
",
)
.stderr(
"
error: Attribute key `pattern` requires value
——▶ justfile:1:13
1 │ [arg('bar', pattern)]
│ ^^^^^^^
",
r"Error: Attribute key `pattern` requires value
╭─[ justfile:1:13 ]
1 │ [arg('bar', pattern)]
───╯
",
)
.failure();
}
Expand All @@ -373,13 +363,12 @@ fn short_requires_value() {
",
)
.stderr(
"
error: Attribute key `short` requires value
——▶ justfile:1:13
1 │ [arg('bar', short)]
│ ^^^^^
",
r"Error: Attribute key `short` requires value
╭─[ justfile:1:13 ]
1 │ [arg('bar', short)]
───╯
",
)
.failure();
}
Expand All @@ -394,13 +383,12 @@ fn value_requires_value() {
",
)
.stderr(
"
error: Attribute key `value` requires value
——▶ justfile:1:19
1 │ [arg('bar', long, value)]
│ ^^^^^
",
r"Error: Attribute key `value` requires value
╭─[ justfile:1:19 ]
1 │ [arg('bar', long, value)]
───╯
",
)
.failure();
}
Loading