diff --git a/cwltool/job.py b/cwltool/job.py index 9dd5b6662..06cbbb502 100644 --- a/cwltool/job.py +++ b/cwltool/job.py @@ -307,6 +307,12 @@ def stderr_stdout_log_path( stderr_path = stderr_stdout_log_path(self.base_path_logs, self.stderr) stdout_path = stderr_stdout_log_path(self.base_path_logs, self.stdout) commands = [str(x) for x in runtime + self.command_line] + if not commands: + raise WorkflowException( + "Cannot run a CommandLineTool that produces an empty command line. " + "Specify a 'baseCommand', 'arguments', and/or an input with an " + "'inputBinding' so there is a program to execute." + ) if runtimeContext.secret_store is not None: commands = cast( list[str], diff --git a/tests/test_examples.py b/tests/test_examples.py index 28245b905..c79f246f7 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -990,6 +990,26 @@ def test_glob_expr_error(tmp_path: Path) -> None: assert "Resolved glob patterns must be strings" in stderr +def test_empty_command_line_error() -> None: + """A CommandLineTool with an empty command line fails cleanly, not with an IndexError.""" + error_code, _, stderr = get_main_output([get_data("tests/wf/no-basecommand.cwl")]) + assert error_code != 0 + stderr = re.sub(r"\s\s+", " ", stderr) + assert "empty command line" in stderr + assert "IndexError" not in stderr + + +@needs_docker +def test_empty_command_line_container_noerror() -> None: + """A CommandLineTool with an empty command line fails cleanly, not with an IndexError.""" + error_code, _, stderr = get_main_output( + ["--default-container", "debian:stable-slim", get_data("tests/wf/no-basecommand.cwl")] + ) + assert error_code == 0 + assert "empty command line" not in stderr + assert "IndexError" not in stderr + + def test_format_expr_error() -> None: """Better format expression error.""" error_code, _, stderr = get_main_output( diff --git a/tests/wf/no-basecommand.cwl b/tests/wf/no-basecommand.cwl new file mode 100644 index 000000000..657fda743 --- /dev/null +++ b/tests/wf/no-basecommand.cwl @@ -0,0 +1,8 @@ +#!/usr/bin/env cwl-runner +# Regression fixture for https://github.com/common-workflow-language/cwltool/issues/1618 +# A CommandLineTool with no baseCommand/arguments/input bindings produces an empty +# command line; running it should fail with a clear error, not a raw IndexError. +cwlVersion: v1.2 +class: CommandLineTool +inputs: [] +outputs: []