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
6 changes: 6 additions & 0 deletions cwltool/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
20 changes: 20 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions tests/wf/no-basecommand.cwl
Original file line number Diff line number Diff line change
@@ -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: []
Loading