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

Show HCL parsing errors and typos #1200

Merged
merged 12 commits into from Mar 11, 2016
Merged

Show HCL parsing errors and typos #1200

merged 12 commits into from Mar 11, 2016

Conversation

sethvargo
Copy link
Contributor

This PR makes Vault's UX around bad HCL keys and errors a little bit better by clearly calling out the line number where a violation occurred and the violation itself.

You can take a look at the added tests to understand what the output looks like, but here are some examples:

$ echo 'path "/" { foo = "bar" }' > policy.hcl
$ vault policy-write test policy.hcl
* Failed to parse policy: 1 error(s) occurred:
* path "/": invalid key 'foo' on line 1

$ echo 'path "/" { policy = "nope" }' > policy.hcl
$ vault policy-write test policy.hcl
* Failed to parse policy: path "/": invalid policy 'nope'

$ echo 'path "/" { capabilities = ["read", "foo"] }' > policy.hcl
$ vault policy-write test policy.hcl
* Failed to parse policy: path "/": invalid capability 'foo'

Thanks @jefferai for helping and @mitchellh for teaching me all the HCL insides!

This does NOT apply to the backend config, since each backend config
could have a variation of options that differ based off of the
configured backend itself. This may be an optimization that can be made
in the future, but I think each backend should be responsible for
performing its own configuration validation instead of overloading the
config itself with this functionality.
This was a flawed test. Previously the test passed in a fixture that
corresponded to a CLI config file, not an actual policy. The test
_should_ have been failing, but it wasn't. This commit adds a new
fixture.
jefferai added a commit that referenced this pull request Mar 11, 2016
@jefferai jefferai merged commit 4a19749 into master Mar 11, 2016
@jefferai jefferai deleted the sethvargo/hcl_errors branch March 11, 2016 03:31
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

Successfully merging this pull request may close these issues.

None yet

2 participants