Skip to content

Commit ebe4ff9

Browse files
sbryngelsonclaude
andcommitted
Fix --step input validation and clarify inclusive range in docs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fd34eed commit ebe4ff9

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

docs/documentation/visualization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The `--step` argument accepts several formats:
4343
| Format | Example | Description |
4444
|--------|---------|-------------|
4545
| Single | `--step 1000` | One timestep |
46-
| Range | `--step 0:10000:500` | Start:end:stride |
46+
| Range | `--step 0:10000:500` | Start:end:stride (inclusive) |
4747
| All | `--step all` | Every available timestep |
4848

4949
### Rendering options

toolchain/mfc/viz/viz.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@ def _parse_steps(step_arg, available_steps):
2323
if step_arg is None or step_arg == 'all':
2424
return available_steps
2525

26-
if ':' in str(step_arg):
27-
parts = str(step_arg).split(':')
28-
start = int(parts[0])
29-
end = int(parts[1])
30-
stride = int(parts[2]) if len(parts) > 2 else 1
31-
requested = list(range(start, end + 1, stride))
32-
return [s for s in requested if s in set(available_steps)]
33-
34-
single = int(step_arg)
26+
try:
27+
if ':' in str(step_arg):
28+
parts = str(step_arg).split(':')
29+
start = int(parts[0])
30+
end = int(parts[1])
31+
stride = int(parts[2]) if len(parts) > 2 else 1
32+
requested = list(range(start, end + 1, stride))
33+
return [s for s in requested if s in set(available_steps)]
34+
35+
single = int(step_arg)
36+
except ValueError:
37+
cons.print(f"[bold red]Error:[/bold red] Invalid --step value '{step_arg}'. "
38+
"Expected an integer, a range (start:end:stride), or 'all'.")
39+
sys.exit(1)
40+
3541
if available_steps and single not in set(available_steps):
3642
return []
3743
return [single]
@@ -87,11 +93,16 @@ def viz(): # pylint: disable=too-many-locals,too-many-statements,too-many-branc
8793
cons.print("[bold red]Error:[/bold red] No timesteps found.")
8894
sys.exit(1)
8995

90-
if step_arg is None:
96+
if step_arg is None or step_arg == 'all':
9197
step = steps[0]
9298
cons.print(f"[dim]Using first available timestep: {step}[/dim]")
9399
else:
94-
step = int(step_arg)
100+
try:
101+
step = int(step_arg)
102+
except ValueError:
103+
cons.print(f"[bold red]Error:[/bold red] Invalid --step value '{step_arg}'. "
104+
"Expected an integer or 'all'.")
105+
sys.exit(1)
95106

96107
if fmt == 'silo':
97108
from .silo_reader import assemble_silo # pylint: disable=import-outside-toplevel

0 commit comments

Comments
 (0)