Skip to content

Feature request: Improve validation error message for task INT parameter range expressions #129

@ddneilson

Description

@ddneilson

Use Case

The error message that is provided for a bad range expression for an INT type task parameter does not currently help the end-user understand what actually went wrong. For example, given:

specificationVersion: jobtemplate-2023-09
name: BadRangeExpr
steps:
  - name: Test
    parameterSpace:
      taskParameterDefinitions:
        - name: P
          type: INT
          range: "1-11:2,11"
    script:
      actions:
        onRun:
          command: bash
          args:
          - "-c"
          - "echo 'Hi'"

The error that we get from validation is:

% openjd check expr.template.yaml 
ERROR: 'expr.template.yaml' failed checks: 1 validation errors for JobTemplate
steps[0] -> parameterSpace -> taskParameterDefinitions[0] -> range:
	Failed to create IntRangeExpr

It points to the right place, but doesn't help someone understand what went wrong. Note that this is different from, say, making a syntax error like range: "1-10:2;10" which produces the error:

% openjd check expr.template.yaml
ERROR: 'expr.template.yaml' failed checks: 1 validation errors for JobTemplate
steps[0] -> parameterSpace -> taskParameterDefinitions[0] -> range:
	Unexpected ';' in '1-10:2;10' after '1-10:2'

There is a better error available, but it is not being surfaced:

% python
Python 3.9.6 (default, Feb  3 2024, 15:58:27) 
[Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import openjd.model._range_expr as r
>>> r1 = r.IntRange(1,10,1)
>>> r2 = r.IntRange(10,10,1)
>>> range_expr = r.IntRangeExpr([r1,r2])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/neilsd/.venv/lib/python3.9/site-packages/openjd/model/_range_expr.py", line 49, in __init__
    self._validate()
  File "/Users/neilsd/.venv/lib/python3.9/site-packages/openjd/model/_range_expr.py", line 153, in _validate
    raise ValueError(
ValueError: Range expression is not valid due to overlapping ranges:
	1-10 overlaps with 10

Proposed Solution

Modify the model validation so that the internal ValueError's message is surfaced rather than the generic "Failed to create IntRangeExpr". i.e. The output should be:

% openjd check expr.template.yaml 
ERROR: 'expr.template.yaml' failed checks: 1 validation errors for JobTemplate
steps[0] -> parameterSpace -> taskParameterDefinitions[0] -> range:
	Not valid due to overlapping ranges:  1-10 overlaps with 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions