Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ pub(crate) enum Error<'src> {
Interrupted {
signal: Signal,
},
InvalidShebang {
recipe: Name<'src>,
shebang: String,
},
ListInStringContext {
context: StringContext<'src>,
value: Value,
Expand Down Expand Up @@ -817,6 +821,9 @@ impl ColorDisplay for Error<'_> {
Interrupted { signal } => {
write!(f, "interrupted by {signal}")?;
}
InvalidShebang { recipe, shebang } => {
write!(f, "recipe `{recipe}` has invalid shebang `{shebang}`")?;
}
ListInStringContext { context, value, .. } => {
write!(f, "list value {} {context}", value.color_display(color))?;

Expand Down
13 changes: 5 additions & 8 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,11 @@ impl<'src> Recipe<'src> {
.unwrap_or_else(|| Interpreter::default_script_interpreter().clone()),
)
} else if self.body.first().is_some_and(Line::is_shebang) {
let line = evaluated_lines
.first()
.ok_or_else(|| Error::internal("evaluated_lines was empty"))?;

let shebang =
Shebang::new(line).ok_or_else(|| Error::internal(format!("bad shebang line: {line}")))?;

Executor::Shebang(shebang)
let shebang = &evaluated_lines[0];
Executor::Shebang(Shebang::new(shebang).ok_or_else(|| Error::InvalidShebang {
recipe: self.name,
shebang: shebang.into(),
})?)
} else {
Executor::Command(
context
Expand Down
14 changes: 14 additions & 0 deletions tests/shebang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,17 @@ fn run_shebang() {
.stderr("error: recipe `a` failed with exit code 200\n")
.status(200);
}

#[test]
fn invalid_shebang_error() {
Test::new()
.justfile(
"
foo:
#!{{ '' }}
echo bar
",
)
.stderr_regex("error: recipe `foo` has invalid shebang `#!`\n")
.failure();
}
Loading