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
1 change: 1 addition & 0 deletions changes.d/7390.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid `initial cycle point` values such as `T, T` now give a clean error message instead of a traceback.
10 changes: 9 additions & 1 deletion cylc/flow/cycling/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,15 @@ def ingest_time(value: str, now: Optional[str] = None) -> str:
timepoint = None
is_truncated = None
else:
timepoint = parser.parse(value)
try:
timepoint = parser.parse(value)
except ISO8601SyntaxError:
raise
except ValueError as exc:
# The parser can fail with a bare ValueError on some malformed
# input (e.g. "T, T"); convert it to a recognisable syntax error
# so callers report it cleanly instead of tracing back.
raise ISO8601SyntaxError('date-time', value) from exc
# missing date-time components off the front (e.g. 01T00)
is_truncated = timepoint.truncated

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/cycling/test_iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
ISO8601Interval,
ISO8601Point,
ISO8601Sequence,
ISO8601SyntaxError,
ingest_time,
)
from cylc.flow.cycling.loader import ISO8601_CYCLING_TYPE
Expand Down Expand Up @@ -963,3 +964,17 @@ def test_validate_fails_comma_sep_offset_list(
set_cycling_type(ISO8601_CYCLING_TYPE, "Z")
with pytest.raises(Exception, match=errortext):
ingest_time(_input)


@pytest.mark.parametrize("_input", ("T, T", "T00, T18", "T00,T18"))
def test_ingest_time_bad_syntax_raises_iso8601_error(_input, set_cycling_type):
"""It raises ISO8601SyntaxError, not a bare ValueError, on bad syntax.

The isodatetime parser fails with an unhelpful "too many values to
unpack" ValueError on some malformed input, which reached the user as a
traceback rather than a clean error message. See
https://github.com/cylc/cylc-flow/issues/7390
"""
set_cycling_type(ISO8601_CYCLING_TYPE, "Z")
with pytest.raises(ISO8601SyntaxError, match="Invalid ISO 8601"):
ingest_time(_input, "2010-08-08T15:41Z")