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

Crash: Unresolved alias (the anchor must be set before the alias) #5186

Closed
eysi09 opened this issue Oct 4, 2023 · 1 comment · Fixed by #5215
Closed

Crash: Unresolved alias (the anchor must be set before the alias) #5186

eysi09 opened this issue Oct 4, 2023 · 1 comment · Fixed by #5215

Comments

@eysi09
Copy link
Collaborator

eysi09 commented Oct 4, 2023

Crash report

Garden crashes if a YAML anchor that's not defined is used. Here's an example config:

    clusterBuildkit:
      cache:
        - type: registry
          tag: _buildcache-main
          registry: *cacheRegistry # <-- This is not defined anywhere

Error message

Encountered an unexpected Garden error. This is likely a bug :fallen_leaf:

You can help by reporting this on GitHub: https://github.com/garden-io/garden/issues/new?labels=bug,crash&template=CRASH.md&title=Crash%3A%20Unresolved%20alias%20(the%20anchor%20must%20be%20set%20before%20the%20alias)%3A%20cacheRegistry

Please attach the following information to the bug report after making sure that the error message does not contain sensitive information:

ReferenceError: Unresolved alias (the anchor must be set before the alias): cacheRegistry
    at Alias.toJSON (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/Alias.js:42:19)
    at Object.toJS (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at Object.addPairToJSMap (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/addPairToJSMap.js:32:34)
    at YAMLMap.toJSON (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/YAMLMap.js:124:28)
    at Object.toJS (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at YAMLSeq.toJSON (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/YAMLSeq.js:76:27)
    at Object.toJS (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at Object.addPairToJSMap (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/addPairToJSMap.js:32:34)
    at YAMLMap.toJSON (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/YAMLMap.js:124:28)
    at Object.toJS (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at Object.addPairToJSMap (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/addPairToJSMap.js:32:34)
    at YAMLMap.toJSON (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/YAMLMap.js:124:28)
    at Object.toJS (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at Object.addPairToJSMap (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/addPairToJSMap.js:32:34)
    at YAMLMap.toJSON (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/YAMLMap.js:124:28)
    at Object.toJS (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at Object.addPairToJSMap (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/addPairToJSMap.js:32:34)
    at YAMLMap.toJSON (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/YAMLMap.js:124:28)
    at Object.toJS (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/nodes/toJS.js:22:26)
    at Document.toJS (/<path-to>/garden-io/garden/core/node_modules/yaml/dist/doc/Document.js:301:26)
    at prepareResource (/<path-to>/garden-io/garden/core/build/src/config/base.js:133:22)
    at /<path-to>/garden-io/garden/core/build/src/config/base.js:114:16

What did you do?

Ran any Garden command.

Your environment

  • OS: macOS Monterey
  • Garden version: Latest main

Frequency

Always.

Workaround

Write correct YAML (it's not as easy as it sounds) :)

@stefreak
Copy link
Member

stefreak commented Oct 9, 2023

The issue is that we only catch errors in loadAndValidateYaml , but apparently with the new YAML parsing library for improved error messages (which is awesome btw!) seems to throw when calling toJS() on the YAML document as well (happens in prepareResource).
We likely should call toJS in loadAndValidateYaml as well and convert it to ConfigurationError.

I think this actually might be a bug in the yaml library; I created an issue upstream: eemeli/yaml#497

@stefreak stefreak changed the title Crash: Unresolved alias (the anchor must be set before the alias): cacheRegistry Crash: Unresolved alias (the anchor must be set before the alias) Oct 9, 2023
github-merge-queue bot pushed a commit that referenced this issue Oct 10, 2023
* chore(deps): update yaml to 2.3.2

* fix: prevent crash due to unresolved alias in yaml

Fixes #5186

* improvement: use loadAndValidateYaml for both kubernetes manifests and
garden configs

test: add tests for loadAndValidateYaml

* improvement: eliminate explicit any in loadAndValidateYaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants