Skip to content

Incorrect error messages for non-string keys (number/null/boolean) in YAML validation #185

Open
@kfess

Description

@kfess

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:

  1. 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
  2. Open the file in VSCode with GitHub Actions extension
  3. 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
  • 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' and The 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.

(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. For false key: Unexpected value 'false' and The 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.

Screenshots
Image

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions