Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ddneilson opened this issue Jul 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ddneilson
Copy link
Contributor

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-10:2,10"
    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
@crowecawcaw crowecawcaw added the enhancement New feature or request label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants