question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

YAML Anchors and References Break Schema Validation and Suggestions

See original GitHub issue

Describe the bug

When user anchors or references in CloudFormation YAML files, schemas stops working when anchors/references are used.

Originally chased with redhat.vscode-yaml in https://github.com/redhat-developer/vscode-yaml/issues/425, but became clear the issue was being caused by this extension.

Since CloudFormation supports anchors and references through the aws cloudformation package path, would it make sense to fix the underlying issue?

Expected Behavior

It works as normal.

Current Behavior

Following error keeps repeating as elements are hovered.

Error thrown while requesting schema "Error: end of the stream or a document separator is expected" when calling the registered contributor "cloudformation"

Steps to Reproduce

  1. Add an anchor to any element
...
 Tags: &tags
   - Key: Application
     Value: MyApp
...

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kddejongcommented, Mar 4, 2021

I was able to replicate the only issue I have is that CloudFormation yaml doesn’t support aliasing.

0reactions
sebastian-fredriksson-bernholtzcommented, Nov 11, 2021

It seems like the main issue impacting me is that Cloudformation Linter causes vscode-yaml validation to be turned off. I’m not sure that the error indicated by the error messages mentioned in the ticket is the cause of my problem.

=== More information ===

@PatMyron You can find the file attached. However, after looking at that PR, I checked the output and found that it detects that it isn’t a Cloudformation file.

I realised that the “yaml.validate” setting is being set to false when the Cloudformation linter is enabled. If I switch it back to true the validation works, despite vscode-yaml still outputting error messages. But it toggles to false again on reload when I have the cfn linter extension enabled. Knowing this makes it much more convenient for me.

Happy to provide any information that can help debug, if you think something still needs to be changed in this extension. Below is a screenshot with the cfn linter output, a screen recording to show what I’m experiencing, and my bitbucket pipeline file.

Screen Shot 2021-11-12 at 00 44 57

https://user-images.githubusercontent.com/14281373/141318766-9d6dea31-b53f-467d-8bae-4b42dab46f43.mp4

Bitbucket pipeline file
definitions:
    services:
        docker:
            memory: 3072

    steps:
        - step: &install-build
              name: Install and Build
              script:
                  - make install
                  - make build
              services:
                  - docker
              caches:
                  - docker
              artifacts:
                  - node_modules/**
                  - src/**
                  - packages.json
                  - package-lock.json
                  - jest.config.js
        - step: &lint
              name: Lint
              script:
                  - make lint
              services:
                  - docker
              caches:
                  - docker
        - step: &test
              name: Test
              script:
                  - export NODE_OPTIONS=--max-old-space-size=3072
                  - make test
              services:
                  - docker
              caches:
                  - docker
        - step: &deploy
              name: Deploy
              script:
                  - source set_env.sh
                  - make deploy
              services:
                  - docker
              caches:
                  - docker
        - step:
              &set-environment-variables # Usage: override 'script' and append commands to set variables into set_env.sh. Then source the set_env.sh file in later steps where you want the variable set.
              name: Set set_env.sh artifact
              artifacts:
                  - set_env.sh

pipelines:
    default:
        - step:
              <<: *set-environment-variables
              script:
                  - echo export TARGET_DEPLOYMENT_ENVIRONMENT="staging" >> set_env.sh
        - step: *install-build
        - parallel:
              - step: *lint
              - step: *test
        - step:
              <<: *deploy
              trigger: manual
              deployment: staging
              name: Deploy to Staging (Manual)
    branches:
        staging:
            - step:
                  <<: *set-environment-variables
                  script:
                      - echo export TARGET_DEPLOYMENT_ENVIRONMENT="staging" >> set_env.sh
            - step: *install-build
            - parallel:
                  - step: *lint
                  - step: *test
            - step:
                  <<: *deploy
                  name: Deploy Staging
                  deployment: staging
        uat:
            - step:
                  <<: *set-environment-variables
                  script:
                      - echo export TARGET_DEPLOYMENT_ENVIRONMENT="uat" >> set_env.sh
            - step: *install-build
            - parallel:
                  - step: *lint
                  - step: *test
            - step:
                  <<: *deploy
                  name: Deploy UAT
                  deployment: uat
        preview:
            - step:
                  <<: *set-environment-variables
                  script:
                      - echo export TARGET_DEPLOYMENT_ENVIRONMENT="preview" >> set_env.sh
            - step: *install-build
            - parallel:
                  - step: *lint
                  - step: *test
            - step:
                  <<: *deploy
                  name: Deploy Preview
                  deployment: preview
        prod:
            - step:
                  <<: *set-environment-variables
                  script:
                      - echo export TARGET_DEPLOYMENT_ENVIRONMENT="prod" >> set_env.sh
            - step: *install-build
            - parallel:
                  - step: *lint
                  - step: *test
            - step:
                  <<: *deploy
                  name: Deploy Production
                  deployment: production
                  trigger: manual
Read more comments on GitHub >

github_iconTop Results From Across the Web

YAML Anchors and References Break Schema Validation and ...
Describe the bug When user anchors or references in CloudFormation YAML files, schemas stops working when anchors/references are used.
Read more >
Advanced YAML syntax cheatsheet - Educative.io
Here's what we'll cover today: Validator and Parser; Anchors and Alias; Schemas; Escape Sequences; Separators and Directives; Wrapping up ...
Read more >
YAML Ain't Markup Language (YAML™) revision 1.2.2
Since in a YAML representation, mapping keys are unordered and nodes may be referenced more than once (have more than one incoming “arrow”),...
Read more >
Optimize GitLab CI/CD configuration files
You can't use YAML anchors across multiple files when using the include keyword. Anchors are only valid in the file they were defined...
Read more >
YAML Anchor, Aliases and Merge Keys
Schema -validation of a YAML document is only possible when all references and merge keys are represented. However, it is not that every...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found