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

JS-YAML: unknown tag <!Join> #16

Open
dvonessen opened this issue Oct 7, 2017 · 23 comments
Open

JS-YAML: unknown tag <!Join> #16

dvonessen opened this issue Oct 7, 2017 · 23 comments

Comments

@dvonessen
Copy link

Hi,

Unfortunately I have some problems to validate yaml documents for AWS CloudFormation.
I have following line in my Template:
TemplateURL: !Join ["/", [ !FindInMap [CFNBucket, !Ref "AWS::Region", !Ref "Environment" ], "cfn-generic/s3_single.yaml"]]

Starting with !Join I get following error:
JS-YAML: unknown tag <!Join> at line 37, column 20

Is there a solution to workaround with this, so that I can validate my templates. E.g. CustomTags that are ignored.

@pms1969
Copy link

pms1969 commented Oct 18, 2017

I've run into this myself. I tried adding a custom schema in the workspace setting (which to be fair, I'm not sure is correct, and now can't remember where I nicked it from).

schema (cloudformation.schema.json):

{
    "mapping": [
      "Base64"
    ],
    "scalar": [
      "Ref",
      "Sub",
      "GetAZs",
      "GetAtt",
      "ImportValue",
      "Condition"
    ],
    "sequence": [
      "And",
      "Equals",
      "GetAtt",
      "If",
      "FindInMap",
      "Join",
      "Not",
      "Or",
      "Select",
      "Sub",
      "Split"
    ]
  }

workspace settings:

{
    "json.schemas": [
        {
            "fileMatch": [
                "*.cf.yml"
            ],
            "url": "./cloudformation.schema.json"
        }
    ]
}

I'm not certain it's being picked up, and the error highlighting certainly doesn't disappear.

@adamvoss
Copy link
Owner

@pms1969 I really don't think that is a JSON Schema

@adamvoss
Copy link
Owner

@dthielking In YAML, !Join, !FindInMap, and !Ref are all tags and are used to convey type information.

YAML tags are used to associate meta information with each node. In particular, each tag must specify the expected node kind (scalar, sequence, or mapping).

Since the underling parser does not know what these tags are, it does not know what kind of node they represent to be able to continue with parsing. I have not tested it, but I think the parser we use supports teaching it new types, but that would still leave the issue on how to communicate that information to the parser. (If that is all figured out, then the question becomes what sort of schema you are looking to apply here; ex. the tag-names relevant?)

@purefan
Copy link

purefan commented Oct 19, 2017

is it fair to assume that all !Ref like tags are simply text replacements for values that were defined earlier or elsewhere?
If so, the parser could read a yaml and store the Parameters "table" (Im looking at the specific case of a Serverless definition but it can be more generalized or parameterized) internally, replacing the !<tag> with a type equivalent, for example:

Parameters:
    AppName:
        Type: String
        Description: The name of the application

Resources:
    MyFunction:
        SomeTag: !Ref AppName

In practice "AppName" would be defined by a parameter in a cli call or read from a configuration file or just taken from somewhere, but maybe all the parser needs is to replace !Ref AppName with a value of the type defined in the Parameters section:

Parameters:
    AppName:
        Type: String
        Description: The name of the application

Resources:
    MyFunction:
        SomeTag: "Some random string"

@pms1969
Copy link

pms1969 commented Oct 19, 2017

The original schema doc I had was https://d1742qcu2c1ncx.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.json

Is that more like it??? very naive about json schemas.

@pms1969
Copy link

pms1969 commented Oct 19, 2017

Actually, this seems what I'm looking for http://fungusakafungus.github.io/cloudformation-jsonschema/v0.4/schema.json

But even that doesn't work. Ho hum.

@spiffytech
Copy link

I'm having the same problem with Ansible variable files, which can contain the tag !vault. No type information is possible there because the value is encrypted data. I'd just like VS Code to not red-squiggle the whole rest of my file.

@MikeSummit
Copy link

I opened this issue incorrectly in VSCode issues. But same problem.

microsoft/vscode#41846

@joefiorini
Copy link

As another use case, we use import-yaml-loader in our project, which passes a custom type to js-yaml that defines a !import tag allowing us to include other files. TBH, I really don't think I need this plugin to actually parse the includes, since the referenced values will just be treated like strings anyway.

It seems like the way to solve this would be to allow for a js file in the workspace config directory (or the workspace root) that can export an object that gets passed to js-yaml as the parser options. Is there precedence for anything like this with other vscode extensions?

@greenaussie
Copy link

I'm trying out VSCode, this one is a blocker for me moving from Atom.

@dmakovec
Copy link

Publishing this here in case anybody else stumbles across it. This particular extension has now been replaced by the "YAML Support by Red Hat" extension, which suffers from the same problem out of the box.

There's a reasonably straightforward config workaround for this in that extension:

Taking the list of functions documented at:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html

and checking the readme at:
https://github.com/redhat-developer/vscode-yaml

My solution was to add the following settings to my user/project settings:

"yaml.customTags": [
"!FindInMap sequence",
"!GetAtt",
"!GetAZs",
"!ImportValue",
"!Join sequence",
"!Ref",
"!Select sequence",
"!Split sequence",
"!Sub"
]

Note that while the readme describes the object type capabilities as having an uppercase first letter (Scalar, Sequence, Mapping, Map), I found that this caused the YAML server to crash. Setting it to lower case as above seems to fix the issue.

@Zebradil
Copy link

The approach of @dmakovec is working well. Just added !Equals sequence there:

    "yaml.customTags": [
        "!Equals sequence",
        "!FindInMap sequence",
        "!GetAtt",
        "!GetAZs",
        "!ImportValue",
        "!Join sequence",
        "!Ref",
        "!Select sequence",
        "!Split sequence",
        "!Sub"
    ]

@cheedallarajesh
Copy link

@Zebradil when I add yaml.customTags, i see a message in vscode 'Unknown configuration setting'. Anything i'm missing?

image

@Zebradil
Copy link

Zebradil commented Sep 5, 2018

@cheedallarajesh Looks fine. Are you sure you have YAML extension installed? If so, check extension «contributions» page. There should be all configuration settings added by this extension.

screen shot 2018-09-05 at 22 25 53

@cheedallarajesh
Copy link

Ha!! that's the issue. I could able to add it after installing the extension. Thank you @Zebradil

@jsrice7391
Copy link

I did @Zebradil 's fix and everything worked. I did not even need to have the YAML plugin.

@hgrewalcapp
Copy link

I tried @Zebradil solution. It works fine until I do not enable Ansible plugin.

@nathansegers
Copy link

CloudFormation creates the following YAML when converting from JSON to YAML through the Designer.
JSON

"EndpointConfigName": {
                        "Fn::GetAtt": [
                            "EndpointConfig",
                            "EndpointConfigName,"
                        ]
                    }

YAML

EndpointConfigName: !GetAtt 
        - EndpointConfig
        - EndpointConfigName

This will result in a Sequence instead of a Scalar. Although both are possible. !GetAtt EndpointConfig.EndpointConfigName

To allow this as a valid YAML file in VSCode, update @Zebradil's solution with
!GetAtt sequence

Mine looks like this now

"yaml.customTags": [
        "!Equals sequence",
        "!FindInMap sequence",
        "!GetAtt",
        "!GetAtt sequence",
        "!GetAZs",
        "!ImportValue",
        "!Join sequence",
        "!Ref",
        "!Select sequence",
        "!Split sequence",
        "!Sub"
        ]

@gregt590
Copy link

gregt590 commented Jul 11, 2019

Also worked for me in solving unknown !Ref tag errors in CloudFormation YAML files using linter-js-yaml 1.4.6 by adding the following in config.cson:

"linter-js-yaml":
    customTags: [
      "!Equals sequence"
      "!FindInMap sequence"
      "!GetAtt"
      "!GetAtt sequence"
      "!GetAZs"
      "!ImportValue"
      "!Join sequence"
      "!Ref"
      "!Select sequence"
      "!Split sequence"
      "!Sub"
    ]

@JonTheNiceGuy
Copy link

I had to add "!Base64 mapping" today to the above list. This now makes it:

    "yaml.customTags": [
        "!Equals sequence",
        "!FindInMap sequence",
        "!GetAtt",
        "!GetAtt sequence",
        "!GetAZs",
        "!ImportValue",
        "!Join sequence",
        "!Ref",
        "!Select sequence",
        "!Split sequence",
        "!Sub",
        "!Base64 mapping"
        ]

@Chewbee
Copy link

Chewbee commented Oct 21, 2019

Hello,

I still have the issue
I have the RH extension
I have this : in settings `
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"cSpell.ignoreWords": [
"nativeretweets",
"serverlessrepo"
],
"yaml.customTags": [
"!Equals sequence",
"!FindInMap sequence",
"!GetAtt",
"!GetAZs",
"!ImportValue",
"!Join sequence",
"!Ref",
"!Select sequence",
"!Split sequence",
"!Sub"
],
"yaml.trace.server": "verbose",

}`

AN I still have this : JS-YAML: unknown tag <!Ref> at line 49, column 37 in the problems ;)

Any clues ?

@ssbarnea
Copy link

@Chewbee Ia facing the same error JS-YAML: unknown tag <!encrypted/pkcs1-oaep> at line 8, column 17 when I try to add !encrypted/pkcs1-oaep, I start to think that there is something else overriding out config and thus producing the same error.

@karol-gro
Copy link

@ssbarnea @Chewbee
I had the same issue, but I disabled Ansible plugin. From what I can see also Cloud Code plugin might cause such issues. They both run yaml server in the background, but ignore yaml.customTags settings

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

No branches or pull requests