Skip to content

Conversation

@ddneilson
Copy link
Contributor

What was the problem/requirement? (What/Why)

When the user has a format string in their template that references a template variable that doesn't exist (either at that scope or otherwise) we just provide a generic "symbol unknown" style error message. We can do better.

What was the solution? (How)

Add a recommender based on the edit distance between the unknown symbol and the available symbols at that location. This is mostly targetting typo errors (e.g. "Parm.Foo" instead of "Param.Foo") right now, so we also have a threshold distance to avoid some misleading suggestions.

What is the impact of this change?

Given a template like:

specificationVersion: jobtemplate-2023-09
name: DemoJob
parameterDefinitions:
- name: Foo
  type: INT
steps:
- name: DemoStep
  script:
    actions:
      onRun:
        command: echo
        args:
        - "{{Parm.Foo}}"

We generate the error:

__root__ -> steps[0] -> script -> actions -> onRun -> args[0]:
        Variable Parm.Foo does not exist at this location. Did you mean: Param.Foo

How was this change tested?

I added unit tests to cover the new functionality.

Was this change documented?

No need.

Is this a breaking change?

Nope.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ddneilson ddneilson requested a review from a team as a code owner February 5, 2024 00:14
@ddneilson ddneilson force-pushed the ddneilson/edit_distance branch 3 times, most recently from 3aa8ef6 to eee23f5 Compare February 6, 2024 16:37
Problem:
 When the user has a format string in their template that references a
template variable that doesn't exist (either at that scope or otherwise)
we just provide a generic "symbol unknown" style error message. We can
do better.

Solution:
 Add a recommender based on the edit distance between the unknown symbol
and the available symbols at that location. This is mostly targetting
typo errors (e.g. "Parm.Foo" instead of "Param.Foo") right now, so we
also have a threshold distance to avoid some misleading suggestions.

Result:

Given a template like:

```yaml
specificationVersion: jobtemplate-2023-09
name: DemoJob
parameterDefinitions:
- name: Foo
  type: INT
steps:
- name: DemoStep
  script:
    actions:
      onRun:
        command: echo
        args:
        - "{{Parm.Foo}}"
```

We generate the error:

```
__root__ -> steps[0] -> script -> actions -> onRun -> args[0]:
        Variable Parm.Foo does not exist at this location. Did you mean: Param.Foo
```

Signed-off-by: Daniel Neilson <53624638+ddneilson@users.noreply.github.com>
@ddneilson ddneilson force-pushed the ddneilson/edit_distance branch from eee23f5 to dc0183b Compare February 6, 2024 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants