Skip to content

Commit

Permalink
make it an error in rhai to have empty ops
Browse files Browse the repository at this point in the history
  • Loading branch information
jku20 committed Aug 8, 2024
1 parent 14ba1da commit 8f2a45d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 0 additions & 5 deletions fud2/fud-core/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ impl EmitBuild for RulesOp {
)?;
}

// If the sequences of rules was empty, output a phoney rule creating the desired output.
if self.cmds.is_empty() {
emitter.build_cmd(outputs, "phony", inputs, &[])?;
}

Ok(())
}
}
Expand Down
11 changes: 11 additions & 0 deletions fud2/fud-core/src/script/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub(super) enum RhaiSystemErrorKind {
ExpectedString(String),
ExpectedShell,
ExpectedShellDeps,
EmptyOp,
}

impl RhaiSystemError {
Expand Down Expand Up @@ -90,6 +91,13 @@ impl RhaiSystemError {
}
}

pub(super) fn empty_op() -> Self {
Self {
kind: RhaiSystemErrorKind::EmptyOp,
position: rhai::Position::NONE,
}
}

pub(super) fn with_pos(mut self, p: rhai::Position) -> Self {
self.position = p;
self
Expand Down Expand Up @@ -126,6 +134,9 @@ impl Display for RhaiSystemError {
RhaiSystemErrorKind::ExpectedShellDeps => {
write!(f, "Expected `shell_deps`, got shell. Ops may contain only one of `shell` or `shell_deps` calls, not calls to both")
}
RhaiSystemErrorKind::EmptyOp => {
write!(f, "Error: Op must contain at least one call to `shell` or `shell_deps`.")
}
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion fud2/fud-core/src/script/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,16 @@ impl ScriptContext {
c
}
Some(ShellCommands::Cmds(c)) => c.clone(),
None => vec![],

None => {
// If cmds is empty, then the op doesn't do anything and should be considered
// erroneous.
return Err(RhaiSystemError::empty_op()
.with_pos(pos)
.into());
}
};

let op_name = name.clone();
let config_vars = config_vars.clone();
let op_emitter = crate::run::RulesOp {
Expand Down

0 comments on commit 8f2a45d

Please sign in to comment.