Description
Describe the bug
The GitHub Actions VSCode extension displays incorrect error messages when YAML files contain non-string keys (numbers, null, boolean values). While the actual GitHub Actions runner properly handles or provides meaningful errors for these cases, the VSCode extension shows different, often misleading error messages.
To Reproduce
Steps to reproduce the behavior:
- Create a workflow files with these YAML contents:
# for numeric key on: push jobs: 1: # numeric key runs-on: ubuntu-latest steps: - run: echo test # for null key on: push jobs: null: # null key runs-on: ubuntu-latest steps: - run: echo test # for true/false key on: push jobs: true: # true key (and also for false key) runs-on: ubuntu-latest steps: - run: echo test
- Open the file in VSCode with GitHub Actions extension
- See errors in the editor
Expected behavior
-
Numeric keys (like 1, not "1"): VSCode extension should show the same error as the actual runner
- The actual error message:
The identifier '1' is invalid. IDs may only contain alphanumeric characters, '_', and '-'. IDs must start with a letter or '_' and and must be less than 100 characters.
Actual Run - This extension's message:
i.indexOf is not a function
- The actual error message:
-
null keys (not "null"): VSCode extension should show the same error message to actual runner: Unexpected value ''
- The actual error message:
Unexpected value ''
Actual Run - This extension's message:
Unexpected value 'null'
andThe identifier 'null' is invalid. IDs may only contain alphanumeric characters, '_', and '-'. IDs must start with a letter or '_' and and must be less than 100 characters.
- The actual error message:
(GitHub Actions automatically converts null keys to empty strings.)
- boolean keys (true/false, not "true"/"false"): VSCode extension should not show errors since they are valid as GitHub Actions syntax when stringified.
- The actual error message: No Error for both true/false Actual Run (true), Actual Run (false)
- The extension's message: For
true
key:i.indexOf is not a function
. Forfalse
key:Unexpected value 'false'
andThe identifier 'false' is invalid. IDs may only contain alphanumeric characters, '_', and '-'. IDs must start with a letter or '_' and and must be less than 100 characters.
Package/Area
- Expressions
- Workflow Parser
- Language Service
- Language Server
Package Version
"version": "0.3.17"
Additional context
The issue appears to be in the implementation of the YAML parser.
In the source code at line 80:
const key = scalarKey.value as string;
The code uses a type assertion (as string) but doesn't actually convert the value to a string type.
When the key is a number, null, or boolean, scalarKey.value retains its original type, causing JavaScript errors when string methods like indexOf are called on it.
Suggested fix example:
const key = scalarKey.value === null ? "" : String(scalarKey.value);
This would properly convert any scalar value to a string, handling:
Numbers: 1 → "1"
Booleans: true → "true", false → "false"
Null: null → "" (empty string)
This fix would ensure proper type conversion and match the behavior of the actual GitHub Actions runner, which automatically stringifies these values when used as keys.
I've verified that the parseWorkflow
function correctly parses files with this fix applied.
I'd be happy to contribute a PR to fix this issue if you think it would be helpful!