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

cfn-cli generate crash due to missing $ref #277

Closed
rjlohan opened this issue Aug 29, 2019 · 2 comments
Closed

cfn-cli generate crash due to missing $ref #277

rjlohan opened this issue Aug 29, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@rjlohan
Copy link
Contributor

rjlohan commented Aug 29, 2019

When I added a malformed schema block, that has a malformed cfn-cli generate crashes. This issue is also not picked up by cfn-cli validate which also crashed.

"namespaceRules": {
	"type": "object",
	"patternProperties": {
	    "^[A-Za-z0-9]{1,64}$": {
	        "$ref": "#/definitions/properties"
	    }
	}
}

(NOTE: #/definitions/properties was a malformed JSON pointer in my schema)

[2019-08-28T18:38:42Z] DEBUG    - Unhandled exception
Traceback (most recent call last):
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/jsonschema/validators.py", line 776, in resolve_fragment
    document = document[part]
KeyError: 'definitions'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/cli.py", line 95, in main
    args.command(args)
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/validate.py", line 14, in validate
    project.load()
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/project.py", line 202, in load
    self.load_schema()
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/project.py", line 165, in load_schema
    self.schema = load_resource_spec(f)
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/data_loaders.py", line 116, in load_resource_spec
    inlined = inliner.inline()
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/jsonutils/inliner.py", line 85, in inline
    self._walk_schema()
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/jsonutils/inliner.py", line 27, in _walk_schema
    self._walk(self.schema, (BASE,))
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/jsonutils/inliner.py", line 52, in _walk
    self._walk(value, old_path + (key,))
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/jsonutils/inliner.py", line 52, in _walk
    self._walk(value, old_path + (key,))
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/jsonutils/inliner.py", line 52, in _walk
    self._walk(value, old_path + (key,))
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/rpdk/core/jsonutils/inliner.py", line 39, in _walk
    url, resolved = self.resolve(value)
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/jsonschema/validators.py", line 734, in resolve
    return url, self._remote_cache(url)
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/jsonschema/validators.py", line 746, in resolve_from_url
    return self.resolve_fragment(document, fragment)
  File "/Users/.../Desktop/CloudFormation/env/lib/python3.7/site-packages/jsonschema/validators.py", line 779, in resolve_fragment
    "Unresolvable JSON pointer: %r" % fragment
jsonschema.exceptions.RefResolutionError: Unresolvable JSON pointer: 'definitions/properties'```
@rjlohan rjlohan added the bug Something isn't working label Aug 29, 2019
@tobywf
Copy link
Contributor

tobywf commented Aug 29, 2019

I think this is related to #66 and aws-cloudformation/cloudformation-resource-schema#23. It would be good to close on this issue. I'm tempted to use something like jsonref to resolve all references before we do anything to check for this kind of situation. but the root cause is again that we are validating the schema as data, not as a schema.

@tobywf tobywf added the low label Oct 10, 2019
@tobywf
Copy link
Contributor

tobywf commented Oct 10, 2019

Short term: catch exception and throw a user-facing exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants