Skip to content

Commit 5d5d68a

Browse files
arimu1claude
andcommitted
Raise a clear error for an empty command line (#1618)
A CommandLineTool with no baseCommand, arguments, or input bindings produces an empty command list. This was passed straight to subprocess.Popen([]), which crashed with a raw "IndexError: list index out of range" deep inside subprocess. Guard the empty case in JobBase._execute and raise a WorkflowException with an actionable message instead. The existing handler turns this into a clean permanentFail rather than an unhandled traceback. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8949fc2 commit 5d5d68a

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

cwltool/job.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ def stderr_stdout_log_path(
307307
stderr_path = stderr_stdout_log_path(self.base_path_logs, self.stderr)
308308
stdout_path = stderr_stdout_log_path(self.base_path_logs, self.stdout)
309309
commands = [str(x) for x in runtime + self.command_line]
310+
if not commands:
311+
raise WorkflowException(
312+
"Cannot run a CommandLineTool that produces an empty command line. "
313+
"Specify a 'baseCommand', 'arguments', and/or an input with an "
314+
"'inputBinding' so there is a program to execute."
315+
)
310316
if runtimeContext.secret_store is not None:
311317
commands = cast(
312318
list[str],

tests/test_examples.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,15 @@ def test_glob_expr_error(tmp_path: Path) -> None:
990990
assert "Resolved glob patterns must be strings" in stderr
991991

992992

993+
def test_empty_command_line_error() -> None:
994+
"""A CommandLineTool with an empty command line fails cleanly, not with an IndexError."""
995+
error_code, _, stderr = get_main_output([get_data("tests/wf/no-basecommand.cwl")])
996+
assert error_code != 0
997+
stderr = re.sub(r"\s\s+", " ", stderr)
998+
assert "empty command line" in stderr
999+
assert "IndexError" not in stderr
1000+
1001+
9931002
def test_format_expr_error() -> None:
9941003
"""Better format expression error."""
9951004
error_code, _, stderr = get_main_output(

tests/wf/no-basecommand.cwl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env cwl-runner
2+
# Regression fixture for https://github.com/common-workflow-language/cwltool/issues/1618
3+
# A CommandLineTool with no baseCommand/arguments/input bindings produces an empty
4+
# command line; running it should fail with a clear error, not a raw IndexError.
5+
cwlVersion: v1.2
6+
class: CommandLineTool
7+
inputs: []
8+
outputs: []

0 commit comments

Comments
 (0)